Display help message with Python argparse when script is called without any arguments

Assume I have a program that uses argparse to process command line arguments/options. The following will print the ‘help’ message:

./myprogram -h

or:

./myprogram --help

But, if I run the script without any arguments whatsoever, it doesn’t do anything. What I want it to do is to display the usage message when it is called with no arguments. How is that done?

18 Answers
18

Leave a Comment