Question re: eval()
Emile van Sebille
emile at fenx.com
Fri Dec 29 12:51:53 EST 2000
What are you trying to do that using a dict doesn't address?
eg:
def n():
return 3
print eval ('n + 1', {'n':n()})
g = {}
l = {}
exec ('m = 4',g,l)
exec ('a = 2',g,l)
print eval ('a + m',g,l)
--
Emile van Sebille
emile at fenx.com
-------------------
"Clarence Gardner" <clarence at netlojix.com> wrote in message
news:978109654.339714327 at news.silcom.com...
>
> 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?
>
> TIA,
> Clarence Gardner
> clarence at netlojix.com
More information about the Python-list
mailing list