[Tutor] How do I add an argument too...

Jeffrey Maitland jeff.maitland at gmail.com
Mon Jul 18 20:02:35 CEST 2005

Well I use the getopt module.

so in my foo.py it would be something like.

import getopt

   opts, args = getopt.getopt(sys.argv[1:], "U:u:P:p:H:h:?",
["Username=", "username=", "Password=", "password=", "Help=","help="])
except getopt.GetoptError:
    print :nothing specila just an error"

for o, a in opts:
   if o in ("-U", "-u",  "--Username", "--username"): username = a
   if o in ("-P", "-p", "--Password", "--password"): password = a
   if o in ("-H", "-h","--Help", "--help","?"): print "foo help"

Hope the example helps. 


More information about the Tutor mailing list