metaprograming on python Namespace object -
I want to assign all the items dynamically But this is not working, how can I get it? Usage: Examples of using Namesapce objects
export_file = {"default_value": "{0} _default_value.txt" .format (args.cam_ip), "msword": "{0} _msword.txt" .format (args. Cam_ip),} args = argparse.Namespace () key, value in export_file.iteritems (): args.key = value
key, value in export_file.iteritems (): setattr (args, key, value)
setattr :
& gt; & Gt; & Gt; Class namespace: ... def __init __ (self): ... self.a = 1 ... & gt; & Gt; & Gt; Ns = namespace ()> gt; & Gt; & Gt; Ns.a 1 & gt; & Gt; & Gt; Settrer (NS, 'A', 9) & gt; & Gt; & Gt; Ns.a 9
Comments
Post a Comment