Referring to class methods in class attributes
mrkafk at gmail.com
Thu Feb 18 10:59:40 CET 2010
Stephen Hansen wrote:
> Or just leave it as a top level function where it was perfectly happy to
> live :)
Yes. This is probably the sanest solution anyway, because probably
having many such functions to use, packing them into smth like
package.utils anyway is a good idea. I'm trying mainly to learn and
test-drive such solutions, not that I would be keen to use them
excessively in production code.
> This obviously means no other method can call it like
> self.print_internal_date(), because self would get passed as first
> argument, yes?
> It doesn't have to be. It could be a class method-- @classmethod does
> that, makes it receive 'cls' the actual class as the first argument. Or
> a @staticmethod, in which case it has no first-argument at all.
Ahh now I get it. Thanks! So that's the use for @staticmethod (I was
wondering if there was any).
More information about the Python-list