Executing bytecode from a string.

Markus von Ehr vonehr at ipm.fhg.de
Mon Aug 23 12:01:40 EDT 2004


Benjamin Scherrey schrieb:

> 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

I am just writing my Macro/Script in python sourcecode.
In the program I'm doing:

f = open('segment.py','r')
str = f.read()
f.close()

segment_code = compile(str, '<string>', 'exec')

exec(segment_code)

Markus



More information about the Python-list mailing list