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 Markus.Amalthea.Magnuson
Recipients Markus.Amalthea.Magnuson
Date 2012-11-04.01:30:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1351992623.71.0.851432414607.issue16399@psf.upfronthosting.co.za>
In-reply-to
Content
If the default value for a flag is a list, and the action append is used, argparse doesn't seem to override the default, but instead adding to it. I did this test script:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
    '--foo',
    action='append',
    default=['bar1', 'bar2']
)
args = parser.parse_args()

print args.foo

Output is as follows:

$ ./argparse_foo_test.py
['bar1', 'bar2']

$ ./argparse_foo_test.py --foo bar3
['bar1', 'bar2', 'bar3']

I would expect the last output to be ['bar3'].

Is this on purpose (although very confusing) or is it a bug?
History
Date User Action Args
2012-11-04 01:30:23Markus.Amalthea.Magnusonsetrecipients: + Markus.Amalthea.Magnuson
2012-11-04 01:30:23Markus.Amalthea.Magnusonsetmessageid: <1351992623.71.0.851432414607.issue16399@psf.upfronthosting.co.za>
2012-11-04 01:30:23Markus.Amalthea.Magnusonlinkissue16399 messages
2012-11-04 01:30:23Markus.Amalthea.Magnusoncreate