I need to make a bunch of class variables and I would like to do it by looping through a list like that:
vars=(\'tx\',\'ty\',\'tz\') #plus plenty more class Foo
The locals() version did not work for me in a class.
locals()
The following can be used to dynamically create the attributes of the class:
class namePerson: def __init__(self, value): exec("self.{} = '{}'".format("name", value) me = namePerson(value='my name') me.name # returns 'my name'