Executing bytecode from a string.

Fredrik Lundh fredrik at pythonware.com
Wed Aug 11 09:03:52 EDT 2004


John Roth wrote:

> Look at the 'new' module. It's in the Library Reference under
> Python Runtime Services. You'll need to wrap the byte string
> with 'code', and then wrap that with 'function'.

that's insane, though.  use marshal on code objects, and keep your
sanity.

see page 4-10 in this document for a small sample:

    http://www.effbot.org/zone/librarybook/data-representation.pdf

to avoid chaos when you upgrade Python, it's a good idea to attach
imp.get_magic() to the marshalled string, and verify it before you un-
marshall the code; see:

    http://mail.python.org/pipermail/python-list/2003-November/196230.html

</F>






More information about the Python-list mailing list