Referring to class methods in class attributes

John Posner jjposner at optimum.net
Wed Feb 17 15:55:35 EST 2010


On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote:
>
> Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO
> beautifully) simple once you get it, but I agree it's a bit peculiar
> when compared to most mainstream OO languages.

Very nice writeup, Bruno -- thanks!

<snip>

>
> class method(object):
>      def __init__(self, func, instance, cls):
>          self.im_func = func
>          self.im_self = instance
>          self.im_class = cls
>
>      def __call__(self, *args, **kw):
>          # XXX : all sanity checks removed for readability
>          if self.im_self:
>              args = (self.im_func,) + args

In the line above, I think you meant:

                args = (self.im_self,) + args

-John



More information about the Python-list mailing list