April 4th, 2004, 09:32 AM
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
now t has to take an argument while the arguments for q and s are optional... does it go something like this?
opts, args = getopt.getopt(sys.argv[1:], "t:qs")
for opt, arg in opts:
if opt == '-t':
if opt == '-q':
if opt == '-s':
April 4th, 2004, 11:22 AM
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