fork download
  1. import argparse
  2. import os.path
  3. parser=argparse.ArgumentParser(prog="ME")
  4. parser.add_argument('--outfile', type=argparse.FileType('w'), default="/tmp/out.txt")
  5. args = parser.parse_args('--outfile /tmp/foo.txt'.split())
  6. print args
  7. assert(os.path.exists('/tmp/foo.txt'))
  8. assert(not os.path.exists('/tmp/out.txt'))
  9.  
Runtime error #stdin #stdout #stderr 0.16s 10040KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 5, in <module>
    args = parser.parse_args('--outfile /tmp/foo.txt'.split())
  File "/usr/lib/python2.7/argparse.py", line 1688, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python2.7/argparse.py", line 1713, in parse_known_args
    default = self._get_value(action, default)
  File "/usr/lib/python2.7/argparse.py", line 2245, in _get_value
    raise ArgumentError(action, msg)
argparse.ArgumentError: argument --outfile: can't open '/tmp/out.txt': [Errno 13] Permission denied: '/tmp/out.txt'