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?
One way to do it is using
sys.argv
. This will print the script name as the first argument and all the other parameters that you pass to it.My solution is entrypoint2. Example:
help text:
The docopt library is really slick. It builds an argument dict from the usage string for your app.
Eg from the docopt readme:
I use optparse myself, but really like the direction Simon Willison is taking with his recently introduced optfunc library. It works by:
So, for example, this function definition:
is turned into this optparse help text: