bytecode - модуль для модификации байткода
http://pypi.python.org/pypi/bytecode/from bytecode import Instr, Bytecode
bytecode = Bytecode()
bytecode.extend([Instr("LOAD_NAME", 'print'),
Instr("LOAD_CONST", 'Hello World!'),
Instr("CALL_FUNCTION", 1),
Instr("POP_TOP"),
Instr("LOAD_CONST", None),
Instr("RETURN_VALUE")])
code = bytecode.to_code()
exec(code)
Hello World!