Let's say you have a string containing a path to a Python script and you want to load and execute that script in transparent way (so that there are not fundamental differences for inner script compared to being run directly via “python path”). And then get the resulting global dict. I thought that runpy.run_path() does this but there are two issues. If the path contains some unicode character then it doesn't work (see http://bugs.python.org/issue17588). And most importantly, given global dict is just a copy of original one, since this original one is purged when temporary module object is garbage collected. So a function object have corrupted __globals__ dict (see http://bugs.python.org/issue18331).
Have you any ideas how to run the inner script?
Update: See my current approach – http://bpaste.net/show/RzAbQxLNXiJsXYm2fplz/ . Any suggestions? Improvements? For example about the details of what can be different from point of view of a script being run. I know about issue with realoading __main__.