[IronPython] Possible bug with exec(code, dict) when using lambdas
Martin Maly
Martin.Maly at microsoft.com
Tue Feb 28 16:36:14 CET 2006
Thanks for the repro, we'll look into it!
Martin
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Giles Thomas
Sent: Tuesday, February 28, 2006 5:20 AM
To: Discussion of IronPython
Subject: [IronPython] Possible bug with exec(code, dict) when using lambdas
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/
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list