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

Roy Smith roy at
Fri Jul 25 18:28:34 CEST 2014

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()
args = parser.parse_args()
print args

$ python  x
Namespace(file_name=None, upload-dir='x')

Roy Smith
roy at

More information about the Python-list mailing list