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>
--
http://mail.python.org/mailman/listinfo/python-list