Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75208
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-07-25 12:28 -0400 |
| Subject | ArgumentParser maps dash to underscore in flags, but not positional arguments? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12316.1406306786.18130.python-list@python.org> (permalink) |
I'm using Python 2.7.3.
It looks like ArgumentParser maps "--foo-bar" to "foo_bar" in the argument namespace, but doesn't do the same kind of mapping for positional arguments. Is this intentional? I can't find in the docs where it describes this mapping, but it's certainly convenient, and seems wrong that it doesn't do it everywhere.
---------------------------------
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("upload-dir")
parser.add_argument("--file-name")
args = parser.parse_args()
print args
---------------------------------
$ python args.py x
Namespace(file_name=None, upload-dir='x')
---
Roy Smith
roy@panix.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
ArgumentParser maps dash to underscore in flags, but not positional arguments? Roy Smith <roy@panix.com> - 2014-07-25 12:28 -0400
csiph-web