A little thought I have had a few times now, so it is time to pass it on for comment.
Basically _every_ time I use getopt, I write code like this:
import getopt try: opts, args = getopt.getopt(sys.argv[1:], "slc:d:e:") except getopt.error, why: print why print usage % (os.path.basename(sys.argv,)) sys.exit(1)
Every single time. I have never used getopt without this code.
How about we put this functionality into getopt itself?
It could be triggered either by adding a new "usage" param defaulting to None, or by adding a new entry point. ie:
opts, args = getopt.getopt(sys.argv[1:], "slc:d:e:", usage=usage)
or opts, args = getopt.getoptex(sys.argv[1:], "slc:d:e:", usage=usage)
I know it is fairly trivial, but IMO is such a useful module and the pattern is used so regularly that is seems to make sense to add it.
Any thoughts? If it is seen favourably, how should we spell it?