importing pyc from memory?

Robert k.robert at gmx.de
Mon Jul 4 12:36:57 EDT 2005


"Derek van Vliet" <dvanvliet at 3dna.net> schrieb im Newsbeitrag
news:1120484279.054832.312150 at g49g2000cwa.googlegroups.com...
> Using the Python/C API, is there a way I can import a pyc file that I
> have in memory (as opposed to loading from disk)?
>
> I'm trying to save compiled python code in a proprietary file format to
> cut reduce the overhead of compiling all my scripts when my app starts
> up.


you can use a zip file as "proprietary file format"? with .pyc's or .py's in
and add the zippath to sys.path ?

other than that you can load the code object of .pyc's content in a string
like

co = marshal.loads( pyc_s[8:] )
mod=imp.new_module('xy')
exec co in mod.__dict__


Robert





More information about the Python-list mailing list