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 py.user
Recipients py.user
Date 2015-06-09.23:05:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1433891109.51.0.989129061245.issue24419@psf.upfronthosting.co.za>
In-reply-to
Content
Action append_const works for options:

>>> import argparse
>>> 
>>> parser = argparse.ArgumentParser()
>>> _ = parser.add_argument('--foo', dest='x', action='append_const', const=42)
>>> _ = parser.add_argument('--bar', dest='x', action='append_const', const=43)
>>> parser.parse_args('--foo --bar'.split())
Namespace(x=[42, 43])
>>>

Action append_const works for single positionals:

>>> import argparse
>>> 
>>> parser = argparse.ArgumentParser()
>>> _ = parser.add_argument('foo', action='append_const', const=42)
>>> _ = parser.add_argument('bar', action='append_const', const=43)
>>> parser.parse_args([])
Namespace(bar=[43], foo=[42])
>>>

Action append_const doesn't work for positionals in one list:

>>> import argparse
>>> 
>>> parser = argparse.ArgumentParser()
>>> _ = parser.add_argument('foo', dest='x', action='append_const', const=42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/site-packages/argparse-1.1-py3.3.egg/argparse.py", line 1282, in add_argument
    """
ValueError: dest supplied twice for positional argument
>>> _ = parser.add_argument('bar', dest='x', action='append_const', const=43)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/site-packages/argparse-1.1-py3.3.egg/argparse.py", line 1282, in add_argument
    """
ValueError: dest supplied twice for positional argument
>>> parser.parse_args([])
Namespace()
>>>


The reason is that a positional argument can't accept dest:

>>> import argparse
>>> 
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('foo', dest='x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/site-packages/argparse-1.1-py3.3.egg/argparse.py", line 1282, in add_argument
    """
ValueError: dest supplied twice for positional argument
>>>
History
Date User Action Args
2015-06-09 23:05:09py.usersetrecipients: + py.user
2015-06-09 23:05:09py.usersetmessageid: <1433891109.51.0.989129061245.issue24419@psf.upfronthosting.co.za>
2015-06-09 23:05:09py.userlinkissue24419 messages
2015-06-09 23:05:09py.usercreate