giving imp.load_module not a real file, HOW?

Christian Heimes lists at cheimes.de
Fri Feb 1 10:45:57 EST 2008


Paul Sijben wrote:
> For some reason imp.load_module insists on getting a real open file as
> the second parameter. I have not able to fool it with stringIO or
> overloaded file objects.
> 
> So now I have two questions:
> 1) why does load_module insist on a real file
> 2) is there a way around it that does not involve (say) tempfile?

imp.load_module is implemented in C. The API expects a file object or a
file descriptor number. Internally the code creates a file pointer *FILE
from a file descriptor. You have to create a temporary file.

Christian




More information about the Python-list mailing list