Does Python have Class methods

Costas Menico costas at meezon.com
Thu May 10 15:14:40 EDT 2001


On Tue, 8 May 2001 21:00:02 +0200, "Alex Martelli" <aleaxit at yahoo.com>
wrote:

>"Aahz Maruch" <aahz at panix.com> wrote in message
>news:9d946l$6m1$1 at panix2.panix.com...
>> In article <3af80f95.73151117 at News.CIS.DFN.DE>,  <costas at meezon.com>
>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. "foo.py") 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
>http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52304, for
>example.  Thomas Heller has also put up a Cookbook recipe, at
>http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52311,
>which exemplifies how to support "real" (Smalltalk-ish) class methods.

I guess a similar concept would apply to class variables? Although I
was under the impression that anything defined in a class outside of a
method, is considered a class variable. Of course I tried it but does
not work.

costas



More information about the Python-list mailing list