Basically, yes, but all the tools built into any support go through the file system.
To do this, you will need to download the source from anywhere, compile it using compile and exec using the __dict__ new module. See below.
I left actually exciting text from the internet and parsing uris etc. as an exercise for the reader (for beginners: I suggest using requests )
In pep 302, this will be the implementation of the loader.load_module function (the parameters are different). You can learn more about this in this import statement.
import imp modulesource = 'a=1;b=2'
At this point, newmodule already a module object in scope, so you do not need to import it or anything else.
modulesource = ''' a = 'foo' def myfun(astr): return a + astr ''' newmod = makemodule(modulesource) print(newmod.myfun('bat'))
Ideal here: http://ideone.com/dXGziO
Tested with python 2, should work with python 3 (uses text compatible printing, uses function-like syntax).
Marcin
source share