[Tutor] getopt question

Xuer linuxasking at netscape.net
Wed Jan 21 04:29:47 EST 2004


an example from 'Python Programming for Beginners'

trygetopt.py
-----------------------------------------------------------------
#!/usr/bin/python

import sys,getopt
try:
        options, xarguments = getopt.getopt(sys.argv[1:],'ha')
except getopt.error:
        pass

print options
------------------------------------------------------------------

./trygetopt.py -ha
get result
[('-h', ''), ('-a', '')]

but ./trygetopt.py -h 123 -a 456
get the result
[('-h', '')]

While I expect the result would be
[('-h', '123'), ('-a', '456')]

what's the matter?
thanks in advance. :)






More information about the Tutor mailing list