argparse and default for FileType

2011-04-08 Thread Paolo Elvati
Hi,

I noticed a "strange" behavior of argparse.
When running a simple code like the following:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
  "-o",
  default = 'fake',
  dest = 'OutputFile',
  type = argparse.FileType('w')
 )
args = parser.parse_args()

I noticed that the default file (fake) is created every time I run the
code, even when I explicitly set the -o flag, in which case it will
produce both files.
My goal instead is to erite the default file ONLY if the flag is not specified.
For the moment, I solved it simply by removing the "default=fake" and
adding the "required=True" keyword, but I was wondering what is the
correct way of doing it (or if it is simply a bug).

Thank you,

Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: argparse and default for FileType

2011-04-12 Thread Paolo Elvati
> Open up a bug report on the Python bug tracker and assign it to the user
> "bethard", who is the author of argparse. He's usually pretty responsive.

Thank you for the answer, I will.



Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list