Executing bytecode from a string.

John Roth newsgroups at jhrothjr.com
Wed Aug 11 08:38:38 EDT 2004


"Benjamin Scherrey" <scherrey at proteus-tech.com> wrote in message
news:pan.2004.08.11.07.18.32.690395 at proteus-tech.com...
> I'm curious as to how difficult it would be to take a string that contains
> compiled bytecode, load it into memory, give it a function name then
> execute that function. I'm thinking of a database that contains compiled
> objects that I can load and execute. I'm also curious as to what level of
> grainularity this would work - module, class, class method, function?
> Anyone tried to do this before? Obviously dependencies are a consideration
> but I'm more interested in the mechanics of this. Appreciate ideas &
> pointers you might have...
>
> Ben Scherrey

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'.

As someone else pointed out, there are a number of other
parameters you'll need to supply, and some of them aren't
at all obvious. You may find the disassembler (documented
under Python language services) to be helpful in figuring
some of them out.

John Roth





More information about the Python-list mailing list