exec with custom dict
anandology at gmail.com
Sat Jun 21 12:28:13 CEST 2008
I am trying to use exec with custom dict.
I am trying to print the value of variable x in 2 places. It is
printing it at the first place and failing at the second place.
def __getitem__(self, key):
return self.get(key, key)
code = """
def f(): return x
env = Env()
Here is the output I'm getting.
Traceback (most recent call last):
File "a.py", line 14, in <module>
File "<string>", line 3, in f
NameError: global name 'x' is not defined
Can somebody explain me what is happening?
More information about the Python-list