Class Methods Vs Any Other Callable
Ivan Illarionov
ivan.illarionov at gmail.com
Thu May 15 00:17:21 EDT 2008
On Wed, 14 May 2008 09:21:10 -0700, vbgunz wrote:
> [...]
> when you see
> one, what is the first thing that comes to mind? When you write one,
> what was the first thing on your mind? Other than "similar to static-
> methods", at what point will you be glad you used one? To sum it up,
> what is the best role for a class-method that does not turn your work
> into code-soup?
The first thing on my mind when I see a classmethod is that I may need a
metaclass here.
class A(object):
@classmethod
def do_something_with_aclass(cls):
pass
@classmethod
def do_something_diffferent_with_aclass(cls):
pass
def do_something(self):
pass
is similar to:
class M(type):
def do_something_with_aclass(cls):
pass
def do_something_diffferent_with_aclass(cls):
pass
class A:
__metaclass__ = M
def do_something(self):
pass
-- Ivan
More information about the Python-list
mailing list