Does Python have Class methods

Magnus Lie Hetland mlh at
Wed May 9 20:42:37 CEST 2001

"Alex Martelli" <aleaxit at> wrote in message
news:9d9fk70gmr at
> "Aahz Maruch" <aahz at> wrote in message
> news:9d946l$6m1$1 at
> > In article <3af80f95.73151117 at News.CIS.DFN.DE>,  <costas at>
> wrote:
> > >
> > >Does Python support the concept of class methods (as opposed to
> > >instance methods)? If not is there a suggested way of doing this?
> >
> > The standard answer is to put the class (e.g. "foo") into its own module
> > (e.g. "") and use module-level functions.
> Right, but that supports "static methods" a la C++ rather than "class
> methods" a la Smalltalk.  Another alternative for "static methods" is at
>, for
> example.  Thomas Heller has also put up a Cookbook recipe, at
> which exemplifies how to support "real" (Smalltalk-ish) class methods.

This is all very fancy and nice, but what is wrong with the following?

  def double(self, x):
      return x*2

  class Doubler:
      double = double

  d = Doubler()
  # returns 6

I remember a discussion earlier on (some years ago) about class variables
where I made a similar remark and someone explained the error of my ways.
Since replying to Alex's posts usually makes me look foolish, I
eagerly await the reply <wink>

> Alex


  Magnus Lie Hetland

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick

More information about the Python-list mailing list