[Python-Dev] Accessing globals without dict lookup
Jeremy Hylton
jeremy@alum.mit.edu
Sun, 10 Feb 2002 00:01:31 -0500
Sun, 10 Feb 2002 00:01:31 -0500
- Previous message: [Python-Dev] Accessing globals without dict lookup
- Next message: [Python-Dev] Accessing globals without dict lookup
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
You can exec a code object and specify the environment to use for
names.
Jeremy
>>> def f():
... print x + y
...
>>> x = 1
>>> y = 3
>>> f()
4
>>> exec f.func_code in {'x':0, 'y':-3}, {}
-3
- Previous message: [Python-Dev] Accessing globals without dict lookup
- Next message: [Python-Dev] Accessing globals without dict lookup
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]