Oddity in 2.4 with eval('None')

M.E.Farmer mefjr75 at hotmail.com
Mon Dec 20 15:38:30 EST 2004


Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', 'shell']
>>> globals()['None']
Traceback (most recent call last):
File "<input>", line 1, in ?
KeyError: None
>>> print None
None
>>> print eval('None')
None
>>> globals()['None']='wassabi'
>>> print None
wassabi
>>> print eval('None')
wassabi
>>> dir()
['None', '__builtins__', '__doc__', '__name__', 'shell']
>>>

I think you are seeing two things and I admit I was confused a bit too.
None is becoming a constant and this is the first step. That is why you
see diffrent results than mine. Also notyice that None didn't exist in
your lnamespace till you defined it then you see all your trouble
start.Shadowing builtins and semi-constants are a bad thing
M.E.Farmer




More information about the Python-list mailing list