compiling module from string and put into namespace

Fuzzyman fuzzyman at gmail.com
Sat May 13 16:29:47 EDT 2006


glomde wrote:
> Ok, now I think I know what I need to do.
> I need to create a variable in the calling functions locals.
> So how do I get access to the calles locals dictionary?
> Is it possible?

If your import is used in the current namespace, just use the global
keyword.

Best is if your function just returns the module though, and then you
have bound your name to it exactly as if you had used import.

If you *really* want to poke it into the globals of whereever your
function is called from, you can use :

    sys._getframe(1).globals['name'] = name

(or something like that, you will need to look up the semantics.)

This is a hack really though, just return the module object and bind
the right name to it where you call it from.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml




More information about the Python-list mailing list