exec src in {}, {} strangeness

Stefan Seefeld seefeld at sympatico.ca
Mon Mar 21 05:58:31 CET 2005


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:

 >>> f = ''.join(open('t.py').readlines())
 >>> exec f in {}, {}
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



More information about the Python-list mailing list