why is there no class (static) methods in Python ?

Carel Fellinger cfelling at iae.nl
Mon Jun 18 15:55:57 EDT 2001


Alex Martelli <aleaxit at yahoo.com> wrote:
> "Richard Gruet" <rgruet at intraware.com> wrote in message
> news:3B2D114E.7B39D954 at intraware.com...
...
>> class C:
>>     def staticFoo(x): print x
>>
>> C.staticFoo(1)

> http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52304

according to the faq there is an even shorter spelling of this idiom:

class Callable:
    def __init__(self, callable):
       self.__call__ = callable

this works as the magic method transformation only applies to
class-functions, not to instance-functions.

To me this spelling of the idiom is a tad more readable, besides it
being more efficient as it saves one method call.

Alex, would you prefer me to add a comment to your recipe entry, or
would you rather change the recipe?

-- 
groetjes, carel



More information about the Python-list mailing list