Advanced object persistence?

Guido van Rossum guido at cnri.reston.va.us
Wed Sep 29 08:32:27 EDT 1999


Nolan Darilek <nolan at ethereal.dhis.org> writes:

> Or, at least, it will one day. :) In order to support user
> extensibility, I need to allow for each function's code to persist
> along with the object. I know there is a bytecode compiler, but is
> there a decompiler which extracts functions' source from their
> bytecodes, and if so, does it handle comments and docstrings?

There can't be, because the comments and the user's layout descisions
aren't in the bytecode.  So you'll have to manage the source on your own.

If you want to efficiently save and restore function objects without
recompiling, though, note that the marshal module can marshal code
objects (f.func_code) and that you can turn a code object (e.g. one
you just unmarshalled) into an executable function object using the
'new' module.  This approach will dump core or worse if you feed it
garbage, so you better add some checksum or other security to prevent
users trying to hack your database.

Also note that exec and eval() allow a code object instead of a source 
string.

(I didn't understand your description of your current approach --
maybe you already know all this...)

--Guido van Rossum (home page: http://www.python.org/~guido/)




More information about the Python-list mailing list