[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Possible to import from a cStringIO file object vs. file on disk?

python

2/26/2010 7:49:00 PM

Steve,

> You'll need to write a custom importer. PEP 302 contains the necessary details.

Thanks for pointing me to PEP 302 and the imp module.

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

[1] http://docs.python.org/library/imp.html#imp.l...

python@bdurham.com wrote:
> Is it possible to import from a cStringIO file object (containing
> compiled byte code) vs. a physical file on disk?
>
> I'm thinking that this is possible, given Python's ability to import
> from zip files, but I'm not sure where to look next.
>
> Thank you,
> Malcolm
>


regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us....
Holden Web LLC http://www.hold...
UPCOMING EVENTS: http://holdenweb.event...

--
http://mail.python.org/mailman/listinfo/p...