This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ajstewart
Recipients ajstewart
Date 2016-11-18.15:41:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479483675.86.0.774570236197.issue28734@psf.upfronthosting.co.za>
In-reply-to
Content
I'm writing a wrapper that optionally accepts a file and reads more options from that file. The wrapper then needs to pass all of these options and the file to another program (qsub). Here is a minimal example to reproduce the behavior I'm seeing:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-a')
>>> parser.add_argument('file', nargs='?')
>>> args = parser.parse_args(['-a', '3', 'myFile'])
>>> print(args)
Namespace(file='myFile', a='3')
>>> parser.parse_args(['-a', '4'], namespace=args)
>>> print(args)
Namespace(file=None, a='4')

The behavior I expect is that the file should remain as 'myFile', but it is being wiped out. Is there any way to prevent this, or is this actually a bug?

I can recreate this problem in Python 2.7 and 3.5.
History
Date User Action Args
2016-11-18 15:41:15ajstewartsetrecipients: + ajstewart
2016-11-18 15:41:15ajstewartsetmessageid: <1479483675.86.0.774570236197.issue28734@psf.upfronthosting.co.za>
2016-11-18 15:41:15ajstewartlinkissue28734 messages
2016-11-18 15:41:15ajstewartcreate