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

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -