Why there is a parameter named "self" for classmethod function?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri May 8 20:52:20 EDT 2009
On Thu, 07 May 2009 04:27:15 -0700, Aaron Brady wrote:
>> Can be, but if there's reason enough to keep it with a class, there's
>> no reason not to.
>
> That's a bit of hyperbole; the usual reasons such as code bloat,
> namespace bloat, maintainability etc. all weigh against it. It's just
> that the benefits weigh heavier.
I'm not sure I understand. Whether the function is in the class or
extracted out into the module, it is exactly the same function. (Apart
from an extra level of indentation, and either an unused "self" parameter
or a @staticmethod line.) Same amount of code, same difficulty of
maintainability. Namespace bloat is also the same, the only difference
being which namespace is bloated: the class or the method.
--
Steven
More information about the Python-list
mailing list