Re:Recharging the Python standard library
by jdost on Friday October 11, 2013 @12:07PM
(#6534000)
I also like using argparse. Nice utility library to "power up" helpful scripts.
[ Parent
| on HN ]
Re:Recharging the Python standard library
by vezzy-fnord on Friday October 11, 2013 @12:19PM
(#6534068)
Argument parsing is an essential utility and part of the standard library in all major programming languages, though. Dating back to getopt becoming a standard in C (or earlier?)
Or do you find Python's argument parsing to be especially notable for some reason?
Re:Recharging the Python standard library
by RyanMcGreal on Friday October 11, 2013 @01:10PM
(#6534422)
For a language whose motto is "There should be one - and preferably only one - obvious way to do it", Python has at least four ways to handle command line arguments out-of-the-box:
* sys.argv
* argparse
* optparse
* getopt
There are, of course, additional third party modules (like opster) that also handle arguments.
Re:Recharging the Python standard library
by mattdeboard on Friday October 11, 2013 @02:29PM
(#6534961)
sys.argv is part of the interpreter. The other three are abstractions over it.
optparse is deprecated (kept around for obvious backward-compat reasons)
getopt is just a different API for people who feel more comfortable with C's getopt API and don't want to learn something else
argparse is the CLI option parser for the future.
tl;dr: There is one way to parse command line arguments: sys.argv. But there are a few abstractions of doing that available in the stdlib.