the address of list.append and list.append.__doc__

HYRY ruoyu0088 at gmail.com
Wed Sep 26 04:42:25 EDT 2007


> There's no such thing as an "original method" - what's stored as an
> attribute of the class is a plain function. FWIW, you can get at this
> function quite easily - via the im_func attribute of the method.

I know about im_func, but I tried the im_func attribute of append and
I get error: 'builtin_function_or_method' object has no attribute
'im_func'
a = [1,2,3]
a.append.im_func # error

> Now what I wonder is what you want to do with the internal identifier of
> a function or method ? (please not that the use of the memory address as
> an id is purely an implementation detail of CPython).

I want to use the function( or id of the function) as a key of dict,
d = {}
d[list.append] = "abc"
d[str.find] = "..."

and I want a function f, that return list.append when call as
f(a.append), so I can get the value in d by d[f(a.append)].

And I also find these is interesting, methods of an unmutable object
can be used as key, but methods of a mutable object cannot:

a = [1,2,3]
d[a.append] = "..." # error: list objects are unhashable
b = "123"
d[b.find] = "..." # OK




More information about the Python-list mailing list