Python: how to load (substitute) attribute name from list -


i improve piece of code:

class opt_variable:         pass  var = opt_variable  list = ["name", "value"]  var.list[0] = "xxx" 

i got message:

attributeerror: type object 'opt_variable' has no attribute 'list' 

i use attribute name called defined list.

you can use setattr add attributes objects.

setattr(var, list[0], "xxx") 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -