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

Hrvoje Niksic hniksic at xemacs.org
Wed Sep 26 05:01:06 EDT 2007


HYRY <ruoyu0088 at gmail.com> writes:

> This works, but I think the key of DOC is too long, so I want to use
> the id of list.append.__doc__ as the key; or use the id of
> list.append:

Using the id is not a good idea because id's are not permanent.  Using
list.append as the hash key will work and will internally use the
pointer to produce the hash key, which is probably what you want
anyway.

> So, I asked how to get list.append from a.append

>>> def unbound(meth):
...   return getattr(type(meth.__self__), meth.__name__)
...
>>> unbound(a.append)
<method 'append' of 'list' objects>

> and why id(list.append.__doc__) changes.

Because the doc for builtins is internally kept in a read-only C
string for efficiency.  The Python string is built only when actually
used.



More information about the Python-list mailing list