#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Argparse not generating unknown option error


    I've defined an option which looks like this:

    parser.add_argument('-s', '--seed', type=str,
    help='Set randomization Seed.')
    args = parser.parse_args()

    On the command line I have this mistake: prog -sv

    I would expect an unknown option '-sv' error, instead I get this:

    args.seed = v

    I'm running python 2.7.3

    Has anyone seen this before?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,928
    Rep Power
    481
    The result you get is the result I expect.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    The result you get is the result I expect.
    Is there no way to get argparse to require white-space between an option and it's argument? One of the reasons I'm using argparse is to catch typos like this immediately.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,928
    Rep Power
    481
    You could disallow short form arguments.

    Otherwise, there might be a some method you could override in a subclass.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo