New submission from Nicu Stiurca <supernic2...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue15125>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to