Maybe it's my use of the getopt() function in C/C++ but in my Python scripts, I've always just made do with the native getopt package and it's served me well. Over time, people have encouraged me to look at using ArgParse but I've always been kind of resistant because it was a little mysterious to me. I finally sat down and figured out how to do basic things I do a lot in scripts using getopt and worked up a simple script using ArgParse to do the same thing. There are definitely some advantages to ArgParse!
Here's the gist with this sample: I've made a few updates to the gist as I discover new features of which I want to take advantage:
- Mutually-exclusive options
- Script description
- etc.
I will admit that since I've created this gist, I've been using ArgParse for new scripts. I can't whip out a script using ArgParse from memory yet (which I can do when I use getopt!) but it's becoming easier. I haven't gone back and retrofitted any existing scripts but who knows.
Building on ArgParse
After I wrote this post, I wrote a couple of other new ones which use ArgParse so the example is proven very useful to me:
Comments
Post a Comment