why? __builtins__ key added from eval

William Purcell williamhpurcell at gmail.com
Tue Sep 30 23:04:34 CEST 2008

I want to use eval to evaluate wx.TextCtrl inputs. How can I keep python
from adding the __builtins__ key to mydict when I use it with eval? Other
wise I have to __delitem__('__builtins__') everytime I use eval?

>>> mydict = {'a':2,'b':3}
>>> eval('a*b',mydict)
>>> mydict
{'a': 2, '__builtins__': {'IndexError': <type 'exceptions.IndexError'>,
...(I'll spare you the rest)...}, 'b': 3}

Also, how come eval has this behavior? Is it desirable?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080930/ae55e128/attachment.html>

More information about the Python-list mailing list