Counting number of objects

Andreas Waldenburger geekmail at usenot.de
Mon Jan 26 05:35:51 EST 2009


On Mon, 26 Jan 2009 02:37:37 +0000 Mark Wooding <mdw at distorted.org.uk>
wrote:

> > This looks OK, although I'd suggest using "cls.counter += 1" instead
> > of "a.counter += 1" in the __new__() method. Just seems clearer to
> > me, esp. when you think about subclassing. 
> 
> I'm not sure about clarity, but that would be semantically different.
> The code as written counts all instances of a and its subclasses.
> Your suggestion would count instances of subclasses independently.  I
> don't know which behaviour the OP would prefer, but I don't think
> choosing between them is a matter of clarity.
> 
Oh shoot. I should have known that. I hope I will from now on, at
least. :/

/W


-- 
My real email address is constructed by swapping the domain with the
recipient (local part).



More information about the Python-list mailing list