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

Dan Eloff dan.eloff at gmail.com
Tue Jun 24 04:01:47 CEST 2008


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



More information about the Ironpython-users mailing list