[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

try:
   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"
   sys.exit(1)

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. 

Jeff


More information about the Tutor mailing list