Package gmisclib :: Module gpk_getopt
[frames] | no frames]

Source Code for Module gmisclib.gpk_getopt

 1  import getopt 
 2   
3 -def parse(arglist, shortoptions, longoptions) :
4 """Splits apart an command line argument list, and puts the arguments into a dictionary. 5 The arguments are a list to be parsed, a string of short one character options, 6 and a list of long gnu-style options. The function returns a dictionary 7 mapping between option names and values (if any). Names in the dictionary 8 have had leading dashes removed. """ 9 10 optlist, args = getopt.getopt(arglist, shortoptions, longoptions) 11 optdict = {}; 12 13 def add_to_dict(x, d=optdict) : 14 k, v = x 15 while(k[0]=='-') : 16 k = k[1:] 17 d[k] = v
18 19 map(add_to_dict, optlist) 20 return (optdict, args) 21