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():
for v in vars:
setattr(no_idea_what_should_go_here,v,0)
is it possible? I don't want to make them for an instance (using self in the __init__) but as class variables.
You can run the insertion code immediately after a class is created:
Also, you can dynamically store the variable while the class is being created:
Late to the party but use the
type
class constructor!If for any reason you can't use Raymond's answer of setting them up after the class creation then perhaps you could use a metaclass: