Currently when I enter invalid options or omit positional arguments, argparse kicks me back to the prompt and displays the usage for my app. This is ok, but I would rather automatically display the full help listing (that explains the options, etc) than require the user to type
./myscript.py -h
Thanks!
Jamie
Best Answer
To print help you might want to use:
print_help
function onArgumentParser
instanceTo print help message on error you need to create own subclass of
ArgumentParser
instance, that overrideserror()
method. For example like that:When this parser encounters unparseable argument line it will print help.