Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75208 > unrolled thread

ArgumentParser maps dash to underscore in flags, but not positional arguments?

Started byRoy Smith <roy@panix.com>
First post2014-07-25 12:28 -0400
Last post2014-07-25 12:28 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  ArgumentParser maps dash to underscore in flags, but not positional arguments? Roy Smith <roy@panix.com> - 2014-07-25 12:28 -0400

#75208 — ArgumentParser maps dash to underscore in flags, but not positional arguments?

FromRoy Smith <roy@panix.com>
Date2014-07-25 12:28 -0400
SubjectArgumentParser maps dash to underscore in flags, but not positional arguments?
Message-ID<mailman.12316.1406306786.18130.python-list@python.org>
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


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web