Import module stored in a cStringIO data structure vs. physical disk file
        Posted  
        
            by Malcolm
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Malcolm
        
        
        
        Published on 2010-05-03T21:57:53Z
        Indexed on 
            2010/05/03
            22:48 UTC
        
        
        Read the original article
        Hit count: 296
        
Is there a way to import a Python module stored in a cStringIO data structure vs. physical disk file?
It looks like "imp.load_compiled(name, pathname[, file])" is what I need, but the description of this method (and similar methods) has the following disclaimer:
Quote: "The file argument is the byte-compiled code file, open for reading in binary mode, from the beginning. It must currently be a real file object, not a user-defined class emulating a file." [1]
I tried using a cStringIO object vs. a real file object, but the help documentation is correct - only a real file object can be used.
Any ideas on why these modules would impose such a restriction or is this just an historical artifact?
Are there any techniques I can use to avoid this physical file requirement?
Thanks, Malcolm
© Stack Overflow or respective owner