|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
need help with getopt
i can't seem to understand how to get it to work properly
let's say i have a program program.py that takes 3 options -t -q -s now t has to take an argument while the arguments for q and s are optional... does it go something like this? try: opts, args = getopt.getopt(sys.argv[1:], "t:qs") except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt == '-t': #do something if opt == '-q': #do something if opt == '-s': #do something |
|
#2
|
|||
|
|||
|
As far as I can see, your code is correct. You say you are you having problems getting it working - what is it doing (or not doing)?
A couple of suggestions: 1) if you wrap your code in the post with [CODE] tags then it will be easier for the rest of us to read. 2) You use the name 'args' for the non-option parameters returned from the getopt function, and 'arg' for the value of the option. These could be easily confused, since they are quite different things. I would suggest renaming 'arg' to 'value' or 'optionValue' or something similar. Dave - The Developers' Coach |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > need help with getopt |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|