[Tutor] getopt matching incorrect options

Jay Loden python at jayloden.com
Tue Jul 12 04:30:49 CEST 2005


I have an app that takes a command line argument of -l or --list.  It uses the 
getopt module to parse the arguments, and I just noticed that for some 
reason, getopt is matching "--lis" or "--li" etc to "--list". (Code pasted in 
below)

Is this normal behavior, and if so, is there any way to avoid this? I just 
want it to match "--list" to "--list", not "--l" and "--li" and "--lis" etc. 

-Jay


###### Code chunk below ######

 try:
                options,args = getopt.getopt(sys.argv[1:], "Rf:shvl", ["list", 
"full-restart=", "full-restart-all", "status-all", "help", "version"])
        
 except getopt.GetoptError:
                # print help information and exit:
                usage()
                sys.exit(2)

                if opt in ("-l", "--list"):
                        listServices(svcs)
                        sys.exit()


More information about the Tutor mailing list