hi there,
I have trouble running some python code with 'exec':
t.py contains:
class Foo: pass
class Bar:
f = Foo
From a python shell I do:
[color=blue][color=green][color=darkred]
>>> f = ''.join(open('t .py').readlines ())
>>> exec f in {}, {}[/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 2, in ?
File "<string>", line 3, in Bar
NameError: name 'Foo' is not defined
However, when I use the current global and local scope, i.e.
simply 'exec f', everything works fine. What am I missing ?
Thanks,
Stefan
I have trouble running some python code with 'exec':
t.py contains:
class Foo: pass
class Bar:
f = Foo
From a python shell I do:
[color=blue][color=green][color=darkred]
>>> f = ''.join(open('t .py').readlines ())
>>> exec f in {}, {}[/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 2, in ?
File "<string>", line 3, in Bar
NameError: name 'Foo' is not defined
However, when I use the current global and local scope, i.e.
simply 'exec f', everything works fine. What am I missing ?
Thanks,
Stefan
Comment