Why is my keyword argument not recognized?

22 views
Skip to first unread message

Terrence Brannon

unread,
Sep 21, 2013, 3:52:18 PM9/21/13
to argh-...@googlegroups.com
I have a function called main with this signature

def main(users, after_login='category_smart_phone', item_title=None):
   ...

And it is being called like so:

if __name__ == '__main__':
    argh.dispatch_command(main)


But when I invoke it like this:
python main.py --item_title Samsung all

I get this error:

usage: main.py [-h] [-a AFTER_LOGIN] [-i ITEM_TITLE] users
main.py: error: unrecognized arguments: --item_title all

So shouldnt --item_title Samsung be --item_title=Samsung? Neither usage works only "-i Samsung"


Andy Mikhailenko

unread,
Sep 21, 2013, 4:41:03 PM9/21/13
to argh-...@googlegroups.com
Hello Terrence,

underscores are very uncommon in CLI arguments; Argh tries to follow
the conventions and automatically converts underscores to dashes.
Therefore, function argument `foo_bar` becomes command argument
`--foo-bar`.

In your case any of these should work:

$ ./main.py --item-title Samsung all
$ ./main.py --item-title=Samsung all
$ ./main.py all --item-title Samsung
$ ./main.py -i Samsung all

Please show more of your script in case `-i foo` won't work even if
there's no other argument which name also starts with an `i`.

Andy

P.S.: I think I'll need to check if the documentation covers this behaviour.
Reply all
Reply to author
Forward
0 new messages