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

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c++ - CryptStringToBinary API behavior -