Python optparse parameter value

How can I accept the opt result

opt, args = parser.parse_args() 

and put it in a dict? A Python call selects an "instance of values", and I cannot find a way to turn an instance of values ​​into a list or dict. Therefore, you cannot copy elements from opt,

 for i in opt: myDict[i] = opt[i] 

instead its clumsy,

 myDict[parm1] = opt.parm1 myDict[parm2] = opt.parm2 

which implies that every time I add a parameter, I must also update this code; there must be a way to let this take care of itself.

+47
python dictionary optparse
Nov 18 '09 at 3:31
source share
1 answer
 options, args = parser.parse_args() option_dict = vars(options) 

(The source is a post for python ideas.)

+83
Nov 18 '09 at 3:34
source share



All Articles