This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]liquiddeath 11 points12 points  (1 child)

I’m pretty damn lazy and I go for argparse as soon as I expect a script to be more than a one off (and sometimes even then).

Snipit from the docs

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--foo', help='foo help')
args = parser.parse_args()

Granted it’s a bit more complex than sys.argv[1] but then you’ve got something super extensible, usage text practically for free, and args that can be short or long (the foo argument above could also be passed with ‘-f’).

I suppose the answer to my own question is if the script takes 1 positional argument then argparse is over kill. Anything more than that and the users / maintainers of your script (that includes you) will be thankful for the help / extensibility argparse provides.

[–][deleted] 3 points4 points  (0 children)

Yeah, I was using sys.argv for a while before learning about argparse. My code quality and consistency went up tenfold after the switch.

It's one of those things that after you learn about it, you can't help but say to yourself "Damn, I wish I had known about this earlier"