Created
June 16, 2010 17:17
-
-
Save daeken/440975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imp, marshal | |
def moduleFromData(name, data): | |
""" | |
Loads a module from a pyc string in memory. | |
`name` -- Name of the module | |
`data` -- Contains the contents of a pyc file in a string | |
Returns a module object | |
""" | |
code = marshal.loads(data[8:]) | |
locals = {} | |
eval(code, {}, locals) | |
module = imp.new_module(name) | |
for k, v in locals.items(): | |
setattr(module, k, v) | |
return module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment