[Tutor] Class vs. Static Methods
alan.gauld at freenet.co.uk
Thu Jun 23 00:59:52 CEST 2005
> class Shape(object):
> _count = 0
> def count(cls):
> cls._count += 1
> except AttributeError:
> cls._count = 1
Ah, clever. This is where I thought I'd need an if/elif
chain, adding a new clause for each subclass. i never thought of
using a try/except to add an attribute to subclasses based on cls.
I like it.
Thanks again Kent.
More information about the Tutor