Whats the best way to reset class attributes in Python.
I have a class whichs has about 20 class attributes, in my init I have
class MyClass:
def __init__(self)
self.time=0
self.pos=0
self.vel=0
self.acc=0
self.rot=0
self.dyn=0
These need to be reset on each iteration of my program, what is the neatest way of doing this rather than setting to zero as shown above
Thanks
I'd rather not reset them in the
init
method but define areset
method for this, and callreset
frominit
and before every subsequent iteration.you can use vars() to return a dictionary of values that you can edit.
something like that
if you dont want to edit some other attributes you can do something like that
this will not edit the variable a , although i think we have gone to far with this and we might be breaking an oop principle here :)
I'm not sure if this any more neat, but:
As SilentGhost suggested, you should probably put them in a sane data structure, such as tuple e.g.
or, you can use dictionary: