question about exec() and compile()

Lance Ellinghouse (lance@markv.com)
Sun, 12 Sep 93 16:02:53 PDT

I have a file that looks like this:
t = 1

def Test():
print 't = ' + `t`

def test2():
print 'calling Test()'
Test()

I read in the file and want to execute test2().

So I do the following:

f = open('file','r')
a = f.read()
f.close()
a_c = compile(a,'<string>','exec')
local_ns = {}
global_ns = {}
exec(a_c,global_ns,local_ns)

Now if I dump local_ns, it shows 't', 'Test' and 'test2' as being
members of local_ns. global_ns is still empty.

Now how can I call test2? I have tried local_ns['test2']()
but it says it cannot find 'Test'

I CANNOT use 'import' as this code is actually part of a file
that cannot be run..

Any ideas?????

Thanks!
Lance Ellinghouse
lance@markv.com