Strings comparison
Dusausoy Bruno
bruno.dusausoy at skynet.be
Mon Dec 30 11:20:03 EST 2002
Hi,
I have a problem with strings comparison.
I've pasted the example of the getopt module and I've removed the long
options because I don't need them.
But when I run it, Python gives me errors:
./test.py -h
Traceback (most recent call last):
File "./test.py", line 24, in ?
main()
File "./test.py", line 16, in main
if o in ("-h"):
TypeError: 'in <string>' requires character as left operand
Here is the code :
import getopt, sys
def usage():
print "Ok"
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:")
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
output = None
for o, a in opts:
if o in ("-h"):
usage()
sys.exit()
if o in ("-o"):
output = a
# ...
if __name__ == "__main__":
main()
I'm sure I've made a string comparison mistake but I don't know which
one. Can someone help me ?
Thanks a lot
--
Dusausoy Bruno
bruno.dusausoy at skynet.be
-= Bleue est la mer, blanche est la mort =-
More information about the Python-list
mailing list