Re: getting the state of an object

2012-10-07 Thread Roy Smith
In article <507170e9$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > I've just looked at one of my classes, picked randomly, and the largest > method is twelve lines, the second largest is eight, and the average is > three lines. I took a look at a subtree of the project

Re: getting the state of an object

2012-10-07 Thread Miki Tebeka
> Is there a simple way to get the *ordered* list of instance Here's one way to do it (weather doing it is a good idea or not is debatable): from operator import attrgetter def __init__(self, a, b, c, d): self.a, self.b, self.c, self.d = a, b, c, d get = attrgetter('a', 'b

Re: getting the state of an object

2012-10-07 Thread Chris Angelico
On Sun, Oct 7, 2012 at 7:50 PM, Franck Ditter wrote: > def foo(self) : > (a,b,c,d) = (self.a,self.b,self.c,self.d) > ... big code with a,b,c,d ... > This strikes me as ripe for bug introduction. There's no problem if you're just reading those values, and mutating them is equally fine, but

Re: getting the state of an object

2012-10-07 Thread Oscar Benjamin
On Oct 7, 2012 9:57 AM, "Franck Ditter" wrote: > > 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 ... > What's wrong with the above? I

Re: getting the state of an object

2012-10-07 Thread Chris Rebert
On Sun, Oct 7, 2012 at 1:50 AM, Franck Ditter wrote: > 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 ... I would generally strongly f

getting the state of an object

2012-10-07 Thread Franck Ditter
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