[Python-Dev] getopt helper?
M.-A. Lemburg
mal@lemburg.com
Thu, 30 Sep 1999 09:29:24 +0200
Mark Hammond wrote:
>
> 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[0],))
> 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?
Why not just add a higher level interface ? Something
like CommandLine.py which is included in mxDateTime ?
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 92 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/