Using import in an exec'ed string

Boudewijn Rempt boud at rempt.xs4all.nl
Sun Aug 5 02:59:45 EDT 2001


I'm wondering why, if I give a customized globals
and locals parameter to exec, import doesn't work
anymore (that is, it doesn't anything to the namespace.):


a="""
import string

def f():
	print string.split("aaa aaa")

f()"""

exec(a)

----------------



a="""
import string

def f():
	print string.split("aaa aaa")

f()"""

exec(a, {}, {})


(Note that in the larger program I'm working with,
I don't simply clear globals - I add a few functions
to it, that's all, but it has the same result).

Could anyone enlighten me?


-- 

Boudewijn Rempt  | http://www.valdyas.org 



More information about the Python-list mailing list