Getopt / matching problem

mixo mixo at beth.uniforum.org.za
Tue Mar 19 09:57:33 EST 2002


 From running the command "python  script.py --use=mixo"
I get the result
[('--user', 'mixo')]

Why do I get match? Is there something that I have left out?
If I pass "--u", "--us" to script I get the same result?


Here is a snippet of the code from "script.py"
.
.
.

def options():
   """
   Parses command line arguments
   """
   try:
     opts,args=getopt.getopt(sys.argv[1:],
     'u:d:h:',['date=','help=','user='])
      #the above 2 lines are in one line
   except:
    usage()
    sys.exit(1)


   if (len(args) >=1):
    usage()
    sys.exit(1)

   date = None
   user = None
   print opts
   for op,val in opts:

     if op in ("-u","--user"):
      user=val

     if op in ("-d","--date"):
      date=val

     if op in ("-h","--help"):
      usage()

   return [user,date]
.
.
.
(user,date) = options()




More information about the Python-list mailing list