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
Post a Comment