The following contains a typo
import argparse
parser = argparse.ArgumentParser(prog="abc")
parser.add_argument("--version", action="store-true")
args = parser.parse_args()
See it? I did "store-true" instead of "store_true". When I run the
code I get
Traceback (most recent call last):
File "problem.py", line 6, in <module>
parser.add_argument("--version", action="store-true")
File "/Users/dalke/tmp/argparse.py", line 1264, in add_argument
action = action_class(**kwargs)
TypeError: 'str' object is not callable
I spent some time trying to figure out what I did wrong, before
spotting the "-" instead of the "_" in my code.
Reading the documentation and the code, it appears the goal is to use
strings for most of the cases but also allow argparse users to
"specify an arbitrary action by passing an object that implements the
Action API".
However, strings are not and cannot implement the Action API. Passing
in an unrecognized string will always be an error, and likely be a
typo like mine.
Could you check for the case of passing in an unsupported string and
raise an exception with a more useful error message?
Original issue reported on code.google.com by andrewda...@gmail.com on 18 Oct 2009 at 8:02
Original issue reported on code.google.com by
andrewda...@gmail.com
on 18 Oct 2009 at 8:02