[Tutor] Class vs. Static Methods
Alan G
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
method
> 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!?
Alan G.
More information about the Tutor
mailing list