Question re: eval()

Clarence Gardner clarence at
Fri Dec 29 12:03:49 EST 2000

I want to eval() an expression, but have some of the variables in it be
lazily evaluated.  E.g.,

class D:
    def __getitem__(self, name):
        if name == 'n':
            return 3

d = D()
x = eval('n + 1', d)

but the eval function accepts only a dictionary as the second parameter.
Is there any amazing way to do this?

Clarence Gardner
clarence at

More information about the Python-list mailing list