metaprograming on python Namespace object -


I want to assign all the items dynamically Namesapce objects

But this is not working, how can I get it?

  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    

Usage:

  key, value in export_file.iteritems (): setattr (args, key, value)   

Examples of using 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

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -