I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments.
What are some of the ways Python programmers can do this?
I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments.
What are some of the ways Python programmers can do this?
There is also
argparse
stdlib module (an "impovement" on stdlib'soptparse
module). Example from the introduction to argparse:Usage:
If you need something fast and not very flexible
main.py:
Then run
python main.py James Smith
to produce the following output:
sys.argv
is a list that contains all the arguments passed to the script on the command line.Basically,
Pocoo's click is more intuitive, requires less boilerplate, and is at least as powerful as argparse.
The only weakness I've encountered so far is that you can't do much customization to help pages, but that usually isn't a requirement and docopt seems like the clear choice when it is.
You may be interested in a little Python module I wrote to make handling of command line arguments even easier (open source and free to use) - Commando