Executing bytecode from a string.

Michael Hudson mwh at python.net
Wed Aug 11 07:01:54 EDT 2004


"Benjamin Scherrey" <scherrey at proteus-tech.com> writes:

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

Fairly hard: you'd need to guess or work out all the other parameters
to new.code such as argcount, stacksize,...

> I'm thinking of a database that contains compiled objects that I can
> load and execute. 

You'd likely be much better off storing marshalled code objects than
raw code strings.  Whether that would suffice is hard to say from your
description, but it's probably a good start.

Or just Python source...

> I'm also curious as to what level of grainularity this would work -
> module, class, class method, function?  

I think "it depends".

> Anyone tried to do this before? 

Almost certainly :-)

Cheers,
mwh

-- 
  Ignoring the rules in the FAQ: 1" slice in spleen and prevention 
    of immediate medical care.
                                              -- Mark C. Langston, asr



More information about the Python-list mailing list