<build-in function> incompatible with <function>

Luke luke at deller.id.au
Mon Jan 30 19:57:27 EST 2006


Built-in functions don't bind to classes like regular functions.  Is
this intended?  (I do notice that the Python Reference Manual sec 3.2
under "Class Instance" refers to a "user-defined function").  Any ideas
what the reason is for this distinction between build-in functions and
normal functions?

It's rather inconvenient when implementing some methods (not the whole
class) in a C extension :-(

$ python
Python 2.4.2 (#1, Nov  3 2005, 12:41:57)
[GCC 3.4.3-20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0,
pie-8.7 on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def normal_func(x):
...   return x
...
>>> class foo(object):
...   a = normal_func
...   b = lambda x : x
...   c = abs
...
>>> obj = foo()
>>> obj.a
<bound method foo.normal_func of <__main__.foo object at 0xb7c3766c>>
>>> obj.b
<bound method foo.<lambda> of <__main__.foo object at 0xb7c3766c>>
>>> obj.c
<built-in function abs>




More information about the Python-list mailing list