[issue14149] argparse: Document how to use argument names that are not Python identifiers
Joseph Birr-Pixton added the comment: > I don’t understand, can you rephrase? Sorry, I mean making Namespace subscriptable. eg: >>> v = argparse.Namespace(abc = 123) >>> v Namespace(abc=123) >>> v.abc 123 >>> v['abc'] Traceback (most recent call last): File "", line 1, in TypeError: 'Namespace' object is not subscriptable > add_argument('foo_bar', metavar='foo-bar', ...) This works. Thanks! Cheers, Joe -- ___ Python tracker <http://bugs.python.org/issue14149> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14149] Argparse usage model requires argument names to be python identifiers
New submission from Joseph Birr-Pixton : Say I have an argument with the name 'foo-bar'. Argparse accepts and parses arguments, but Namespace does not allow me to access the value. Yes, I can use getattr or Namespace.__dict__. But that's ugly. Yes, I can change the name of the argument, but that's not what I want in my help output. I think it should either: - Collapse names to valid python identifiers (optparse did this). - Namespace should act like an object and dict. -- components: Library (Lib) files: argparsetest.py messages: 154550 nosy: Joseph.Birr-Pixton priority: normal severity: normal status: open title: Argparse usage model requires argument names to be python identifiers type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file24669/argparsetest.py ___ Python tracker <http://bugs.python.org/issue14149> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com