Here’s a way to use getopt to handle arguments when creating command line applications. It works quite well with the standard help (–help or -h) by showing usage when bad arguments are passed.
#!/bin env python
import sys
def main(argv):
try:
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt == "all":
pass
elif opt == "1":
pass
elif opt == "2":
pass
elif opt == "3":
pass
except getopt.GetoptError:
usage()
sys.exit(2)
2:51 pm
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) - http://freshmeat.net/projects/commando