Message198376
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') |
|
Date |
User |
Action |
Args |
2013-09-25 07:15:01 | paul.j3 | set | recipients:
+ paul.j3, bethard, eric.araujo, Paolo.Elvati, manveru, Stefan.Pfeiffer, David.Layton |
2013-09-25 07:15:01 | paul.j3 | set | messageid: <1380093301.06.0.604701830066.issue13824@psf.upfronthosting.co.za> |
2013-09-25 07:15:01 | paul.j3 | link | issue13824 messages |
2013-09-25 07:15:00 | paul.j3 | create | |
|