Oddity in 2.4 with eval('None')
Fredrik Lundh
fredrik at pythonware.com
Mon Dec 20 16:33:15 EST 2004
Leif K-Brooks wrote
>> Yes. "print eval('None')" is printing the value of None as defined in your module's global
>> namespace:
>
> Right, but why? The expression "None" doesn't worry about the global namespace when used in normal
> code; why does it when used in eval()ed code?
from what I can tell, the mapping of the None symbol to a constant is done
in the peephole optimizer, which doesn't seem to be used when compiling
expressions.
in 2.4:
>>> dis.dis(compile("None", "", "exec"))
1 0 LOAD_CONST 0 (None)
3 POP_TOP
...
>>> dis.dis(compile("None", "", "eval"))
0 0 LOAD_NAME 0 (None)
3 RETURN_VALUE
in 2.3:
>>> dis.dis(compile("None", "", "exec"))
1 0 LOAD_NAME 0 (None)
3 POP_TOP
...
>>> dis.dis(compile("None", "", "eval"))
0 0 LOAD_NAME 0 (None)
3 RETURN_VALUE
</F>
More information about the Python-list
mailing list