Question about math.pi is mutable

BartC bc at freeuk.com
Sun Nov 8 06:19:50 EST 2015


On 08/11/2015 11:02, Marko Rauhamaa wrote:
> Bartc <bc at freeuk.com>:
>
>> (In the case of Python, the main obstacle is that a constant name from
>> inside an imported module is not visible when this module is compiled
>> to byte-code. So it has to assume it can be anything.)
>
> Which it can.
....
> That elegant dynamism comes at a cost: method lookup is not a constant
> memory offset. Rather, it is a dictionary lookup.

I've never understood why this seems to be necessary in Python. Why do 
names have to be looked up? (I'm assuming this is searching by name in 
some sort of table.)

When a module is compiled, while the compiler can't see the definitions 
inside the imported modules, it /will/ know all the names that appear in 
this module, so it can organise them into fixed tables. Then the names 
can be referred to by index. (I think LOAD_FAST does this.)

Or is eval() the culprit here by making most optimisations impossible?

-- 
Bartc



More information about the Python-list mailing list