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.
Created on 2013年05月13日 02:23 by paul.j3, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg189090 - (view) | Author: paul j3 (paul.j3) * (Python triager) | Date: 2013年05月13日 02:23 | |
"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).
|
|||
| msg189457 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年05月17日 14:27 | |
This is a duplicate of issue 15125. (FYI there are many many unix commands that use options of the form -XXX-YYYY. This is the standard for the gnu 'long option' format.) |
|||
| msg189462 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年05月17日 15:30 | |
That should have been --XXX-YYY, of course. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:45 | admin | set | github: 62165 |
| 2013年05月17日 15:30:40 | r.david.murray | set | messages: + msg189462 |
| 2013年05月17日 14:27:19 | r.david.murray | set | status: open -> closed superseder: argparse: positional arguments containing - in name not handled well nosy: + r.david.murray messages: + msg189457 resolution: duplicate stage: resolved |
| 2013年05月15日 21:29:40 | terry.reedy | set | nosy:
+ bethard |
| 2013年05月13日 06:45:16 | paul.j3 | set | title: argparse does not dest.replace('-', '_') for postionals -> argparse does not dest.replace('-', '_') for positionals |
| 2013年05月13日 02:23:29 | paul.j3 | create | |