[Tutor] Class vs. Static Methods
alan.gauld at freenet.co.uk
Thu Jun 23 09:31:59 CEST 2005
> This is a neat trick. But can't this also be done with a static
> that accesses a static data attribute the same way?
I don't think so because the static mehod can only see
the attributes of Shape not of Line. It doesn't have
access to the cls value in Kent's code below...
> >> @classmethod
> >> def count(cls):
> >> try:
> >> cls._count += 1
> >> except AttributeError:
> >> cls._count = 1
So if it tried to incremet count every instance of every
kind of shape would increment the shape counter - which may
be what you want under some circumstances, but it wouldn't
know which of the subclasses was calling it so couldn't
access their counters.
I think thats right!?
More information about the Tutor