Strings comparison

v.wehren v.wehren at home.nl
Mon Dec 30 13:04:12 EST 2002


"Dusausoy Bruno" <bruno.dusausoy at skynet.be> schrieb im Newsbeitrag
news:pan.2002.12.30.17.19.45.927872.7088 at skynet.be...
> 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()

HEY!  You never get any opts, as you neve pass any arguments/options to your
main function!

>
> 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