[IronPython] Possible bug with exec(code, dict) when using lambdas
Giles Thomas
giles.thomas at resolversystems.com
Tue Feb 28 14:19:31 CET 2006
Hi all,
It looks like there may still be outstanding problems with exec(code,
dict) in beta 3; while the context in the dictionary is available to
normal code, anything deferred into a function can't see it.
An example might clarify:
IronPython 1.0.2237 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> context = {}
>>> exec("a = 1", context)
>>> exec("print a", context)
1
>>> exec("b = lambda x : x + a", context)
>>> exec("c = b(5)", context)
Traceback (most recent call last):
File , line 0, in input##105
File , line 0, in <exec>##106
File , line 0, in lambda
You get the same problem if you use a regular function rather than a lambda:
>>> context = {}
>>> exec("a = 1", context)
>>> exec("def b(x): return x + a", context)
>>> exec("c = b(5)", context)
Traceback (most recent call last):
File , line 0, in input##80
File , line 0, in <exec>##81
File , line 0, in b
NameError: name 'a' not defined
>>>
The same code executes as expected in CPython.
Hope this is of some help to someone!
Cheers,
Giles
--
Giles Thomas
Resolver Systems
giles.thomas at resolversystems.com
We're hiring! http://www.resolversystems.com/jobs/
More information about the Ironpython-users
mailing list