Author paul.j3
Recipients David.Layton, Paolo.Elvati, Stefan.Pfeiffer, bethard, eric.araujo, manveru, paul.j3
Date 2013-09-25.07:15:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380093301.06.0.604701830066.issue13824@psf.upfronthosting.co.za>
In-reply-to
Content
An alternative way to delay the file opening, is to return an instance that has a `filename` attribute, and has an `open` method.  This can be compactly added to the `FileContext` that I defined in the previous patch.  The `FileContext` provides the `_ostest` function (testing using os.access), and wrapper for stdin/out.


    class FileOpener(argparse.FileContext):
        # delayed FileType; alt to use of partial()
        # sample use:
        # with args.input.open() as f: f.read()
        def __call__(self, string):
            string = self._ostest(string)
            self.filename = string
            return self
        def open(self):
            return self.__delay_call__(self.filename)()
        file =  property(open, None, None, 'open file property')
History
Date User Action Args
2013-09-25 07:15:01paul.j3setrecipients: + paul.j3, bethard, eric.araujo, Paolo.Elvati, manveru, Stefan.Pfeiffer, David.Layton
2013-09-25 07:15:01paul.j3setmessageid: <1380093301.06.0.604701830066.issue13824@psf.upfronthosting.co.za>
2013-09-25 07:15:01paul.j3linkissue13824 messages
2013-09-25 07:15:00paul.j3create