eval function

Franck Bui-Huu Franck.BUI-HUU at gemplus.com
Thu Apr 24 07:49:39 EDT 2003


Hy,

I would like to use eval function with my own dicts.
For instance :

class my_dict(dict):
    def __getitem__(self, key):
        print 'using my_dict'
        dict.__getitem__(self, key)

 >>> dict = my_dict()
 >>> dict['x'] = 1
 >>> eval('1+x', dict)
2
 >>>

but eval seems to not use __getitem__ method of my_dict object because
"using my_dict" is not printed.
How can I print "using my_dict" when calling eval function ?

Thanks






More information about the Python-list mailing list