getting the state of an object

Franck Ditter franck at ditter.org
Sun Oct 7 04:50:38 EDT 2012


Hi !

Another question. When writing a class, I have often to
destructure the state of an object as in :

def foo(self) :
    (a,b,c,d) = (self.a,self.b,self.c,self.d)
    ... big code with a,b,c,d ...

So I use the following method :

def state(self) :
    return (self.a,self.b,self.c,self.d)

so as to write :

def foo(self) :
    (a,b,c,d) = self.state()
    ... big code with a,b,c,d ...

This is probably not the best Python way to code, is it ?
Is there a simple way to get the *ordered* list of instance
variables as given in the parameter list of __init__ ? 
__dict__ gives it but not in order...
Thanks a lot,

   franck



More information about the Python-list mailing list