生成和修改字节码的python模块
bytecode的Python项目详细描述
bytecode是用于生成和修改字节码的python模块。
- bytecode project homepage at GitHub(代码,错误)
- bytecode documentation
- Download latest bytecode release at the Python Cheeseshop (PyPI)
安装字节码:python3 -m pip install bytecode。它需要Python3.4 或更新的。
执行print('HelloWorld!'):
的示例frombytecodeimportInstr,Bytecodebytecode=Bytecode([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)