Load python module not from a file
Posted
by
user575061
on Stack Overflow
See other posts from Stack Overflow
or by user575061
Published on 2011-01-14T00:28:51Z
Indexed on
2011/01/14
0:53 UTC
Read the original article
Hit count: 175
Hello, I've got some python code in a library that attempts to load a simple value from a module that will exist for the applications that use this library
from somemodule import simplevalue
Normally, the application that uses the library will have the module file and everything works fine. However, in the unit tests for this library the module does not exist. I know that I can create a temporary file and add that file to my path at runtime, but I was curious if there is a way in python to load something in to memory that would allow the above import to work.
This is more of a curiosity, saying "add the module to your test path" is not helpful :P
© Stack Overflow or respective owner