a better getopt than getopt.py?
Timothy Grant
tjg at exceptionalminds.com
Tue Feb 20 11:54:49 EST 2001
I recently went through a very similar experience with getopt,
though I was working on subclassing a class that handled
command line arguments (getopt proved to be completely
unsuitable for that task). I turned to t module I found on
Parnassus called cmdline.py. It works beautifully, as expected,
and the implementation is much more readable than the similar
getopt version.
for some reason it doesn't show up in a Parnassus search for
some reason it doesn't show up in a search for cmdline.py, but
it does show up as one of about three hits in a search for
getopt.
On Mon, Feb 19, 2001 at 05:21:47PM -0800, Sean 'Shaleh' Perry wrote:
> Writing my fisrt real python app that people will run from the command line
> (most of my previous coding has been modules for other software to web stuff)
> I decided to use getopt. My setup looks like this:
>
> LONG_OPTIONS = ['help', 'setup-lab', 'lab=']
> SHORT_OPTIONS = 'hS'
>
> try:
> optlist, args = getopt.getopt(sys.argv[1:], SHORT_OPTIONS,
> LONG_OPTIONS)
> except getopt.error, e:
> print e
> print USAGE
> sys.exit(1)
>
> for option, argument in optlist:
> if option in ('-h', '--help'):
> print USAGE
> sys.exit(0)
> elif option in ('-S', '--setup-lab'):
> print 'Want to set up the lab ...'
> elif option == 'lab':
> print 'Put lab in: ' + argument
>
> this means I have my options defined twice and then once again in the USAGE
> output. Is there not a better way to handle arguments?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
--
Stand Fast,
tjg.
Timothy Grant tjg at exceptionalminds.com
Red Hat Certified Engineer www.exceptionalminds.com
Avalon Technology Group, Inc. (503) 246-3630
>>>>>>>>>>>>>Linux, because rebooting is *NOT* normal<<<<<<<<<
>>>>This machine was last rebooted: 34 days 21:04 hours ago<<
More information about the Python-list
mailing list