Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'argument': 0.05; 'args': 0.07; 'parser': 0.07; 'python': 0.11; 'mapping,': 0.16; 'namespace,': 0.16; 'positional': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.75': 0.16; 'received:166.84.1.89': 0.16; 'received:l2mail1.panix.com': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'to:name:python list': 0.16; 'received:10.0.1': 0.19; 'received:166': 0.19; 'seems': 0.21; 'import': 0.22; 'print': 0.22; 'certainly': 0.24; 'looks': 0.24; '---': 0.24; 'skip:p 30': 0.29; "doesn't": 0.30; "i'm": 0.30; 'skip:- 30': 0.32; "can't": 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'received:10.0': 0.36; 'wrong': 0.37; 'received:10': 0.37; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'header:Message- Id:1': 0.63; 'kind': 0.63; 'smith': 0.68; 'subject:skip:A 10': 0.78; 'describes': 0.84; 'email addr:panix.com': 0.84; 'everywhere.': 0.84 From: Roy Smith Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Fri, 25 Jul 2014 12:28:34 -0400 Subject: ArgumentParser maps dash to underscore in flags, but not positional arguments? To: Python List Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406306786 news.xs4all.nl 2888 [2001:888:2000:d::a6]:45316 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75208 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 =3D ArgumentParser() parser.add_argument("upload-dir") parser.add_argument("--file-name") args =3D parser.parse_args() print args --------------------------------- $ python args.py x Namespace(file_name=3DNone, upload-dir=3D'x') --- Roy Smith roy@panix.com