Normally the unix shell takes care of this expansion. If I call a simple script that prints sys.argv and runs a simple parser, I get:
2135:~/mypy$ python2.7 filetypetest.py ~/mypy/test.txt
['filetypetest.py', '/home/paul/mypy/test.txt']
Namespace(file=<open file '/home/paul/mypy/test.txt', mode 'r'...)
I have to quote the argument '~/mypy/test.blog' to bypass this expansion.
This is under Linux (bash). Is Windows or Mac different?
My impression is that `FileType` has been provided as an example of a custom `type`, as opposed to a comprehensive file handler. But I can't quote a developer on this.
http://bugs.python.org/issue13824 is a bug report that worries that 'argparse.FileType opens a file and never closes it'. There are some comments there about whether it is appropriate to expand on the capabilities of FileType. |