[New-bugs-announce] [issue15125] argparse: positional arguments containing - in name not handled well
Nicu Stiurca
report at bugs.python.org
Thu Jun 21 17:34:07 CEST 2012
New submission from Nicu Stiurca <supernic2002 at gmail.com>:
To reproduce, try the following code:
from argparse import ArgumentParser
a = ArgumentParser()
a.add_argument("foo-bar")
args = a.parse_args(["biz"])
print args, args.foo_bar
Expected output:
Namespace(foo_bar='biz') biz
Actual output:
Namespace(foo-bar='biz')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Namespace' object has no attribute 'foo_bar'
Other comments:
The positional argument 'foo-bar' becomes impossible to retrieve without explicitly passing keyword argument dest='foo_bar'. Hyphens in positional arguments should be automatically replaced with underscores just as with other arguments.
I have not tested if this problem occurs in Python versions newer than 2.6.
----------
messages: 163340
nosy: nstiurca
priority: normal
severity: normal
status: open
title: argparse: positional arguments containing - in name not handled well
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15125>
_______________________________________
More information about the New-bugs-announce
mailing list