Difference between static method and a function as a class attribute?

Martin v. Löwis loewis at informatik.hu-berlin.de
Mon Sep 9 03:48:12 EDT 2002


Gonçalo Rodrigues <op73418 at mail.telepac.pt> writes:

> Haaaa (a light goes on in an otherwise dark and empty skull) so the
> function is implicitely mutated into an unbound method! Wasn't aware of
> this, thought that Python did nothing at all and that is why I asked -
> Always learning new things.

Yes. Guido once phrased this as "functions become methods *on the way
out* of the class". This has surprised me at first as well, but I now
consider it quite elegant, as it allows

C.m = f

where f is a function; C.__dict__['m'] will still be the function, but
C.m will be a method (whose im_func is f).

Regards,
Martin



More information about the Python-list mailing list