New submission from paul j3: "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). ---------- components: Library (Lib) messages: 189090 nosy: paul.j3 priority: normal severity: normal status: open title: argparse does not dest.replace('-', '_') for postionals type: behavior versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17965> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com