Building CPython

Marko Rauhamaa marko at pacujo.net
Fri May 15 18:44:41 EDT 2015


BartC <bc at freeuk.com>:

> What /is/ a method lookup? Is it when you have this:
>
>  A.B()
>
> and need to find whether the expression A (or its class or type) has a
> name B associated with it? (And it then needs to check whether B is
> something that can be called.)
>
> If so, does that have to be done using Python's Dict mechanism? (Ie.
> searching for a key 'B' by name and seeing if the object associated
> with it is a method. That does not sound efficient.)

That is a general feature among high-level programming languages. In
Python, it is even more complicated:

 * first the object's dict is looked up for the method name

 * if the method is not found (it usually isn't), the dict of the
   object's class is consulted

 * if the method is found (it usually is), a function object is
   instantiated that delegates to the class's method and embeds a "self"
   reference to the object to the call

IOW, two dict lookups plus an object construction for each method call.


Marko



More information about the Python-list mailing list