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 paul.j3
Recipients paul.j3
Date 2013-05-13.02:23:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368411809.58.0.522670485437.issue17965@psf.upfronthosting.co.za>
In-reply-to
Content
"16.4.3.11. dest
For optional argument actions,... Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name."

In _get_optional_kwargs(), dest = dest.replace('-', '_'); but there is nothing like this in _get_positional_kwargs()

Thus if

   parser.add_argument('foo-bar',...)

this attribute can only be accessed with 

   getattr(namespace, 'foo-bar').

Alternatives:
- ignore this since no one has complained about it
- stress in the documentation that the positionals name should be a valid python attribute name
- test the name during add_argument
- add the dest.replace('-','_') to positionals

But as things stand, even an optional can be given a weird dest - 

    a=p.add_argument('--foo*[]-bar')

requiring

    getattr(args,'foo*[]_bar')

I assume that optionals have this dash replacement because historically some unix (or other) programs have accepted options like '--foo-bar' (though off hand I can't think of any).
History
Date User Action Args
2013-05-13 02:23:29paul.j3setrecipients: + paul.j3
2013-05-13 02:23:29paul.j3setmessageid: <1368411809.58.0.522670485437.issue17965@psf.upfronthosting.co.za>
2013-05-13 02:23:29paul.j3linkissue17965 messages
2013-05-13 02:23:28paul.j3create