Serializing Python compiled code.

Steve Howell showell30 at yahoo.com
Sun Dec 9 10:49:25 EST 2007


--- renjipanicker at gmail.com wrote:

> In a C++ application having a Python interpreter
> embedded, is it
> possible to compile a small Python snippet into
> object code and
> serialize the compiled object code to, for example,
> a database? I am
> exploring the possibility of writing a data driven
> application, where
> small-sized object code can be read from a database
> and executed.
> Keeping aside all other considerations such as
> security, etc for a
> moment, is this feasible?
> 


This might be too coarse for you, but you could
serialize the .pyc files that get created from your
modules.  If you drop a .pyc file into a directory,
and you make sure that you don't have a corresponding
.py file of the same basename, and new date, in the
directory, then Python will still execute it.

This is a bit of a gotcha of Python for naive users,
but this feature helps in use cases like yours, where
you don't want to pay the lexing step, and for
whatever reason, you don't want to simply use the file
system as your store for code.


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs



More information about the Python-list mailing list