[IronPython] NameError: locals() is not defined?

Dino Viehland dinov at exchange.microsoft.com
Mon Jun 23 19:15:54 PDT 2008


It seems to be fixed in beta 3.  It's probably a bug in the interpreter as writing the snippet out and executing w/ execfile, which doesn't run under the interpreter, works in beta 2 as well.

The reason it got silently fixed was because between the two versions the interpreter was moved from M.S.Core.dll up to M.S.dll and a bunch of bugs were fixed along the way.  In beta 3 the interpreter is also now always used for exec or eval - previously it avoided certain constructs it couldn't support.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Monday, June 23, 2008 7:02 PM
To: Discussion of IronPython
Subject: [IronPython] NameError: locals() is not defined?

In IronPython b2 I get:

>>> s = '''
... def body(context):
...     def ccall():
...             body = lambda: None
...             context.update(locals())
...     ccall()
...
... '''
>>> d = {}
>>> exec s in d
>>> c = {}
>>> d['body'](c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line unknown, in Interpreted_body_1
NameError: name 'locals' is not defined

This works fine in CPython:

>>> s = '''
... def body(context):
...     def ccall():
...             body = lambda: None
...             context.update(locals())
...     ccall()
...
... '''
>>> exec s in d
>>> c = {}
>>> d['body'](c)
>>> c
{'body': <function <lambda> at 0x0359CCB0>, 'context': {...}}

Any idea why?

Thanks,
-Dan
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


More information about the Users mailing list