rocky/python-xasm

Python API ?

Conchylicultor opened this issue · 2 comments

I could not find it on the doc.

Is is possible to dynamically assemble/disassemble from within a program ? Something like:

import dis


instructions = dis.get_instructions(fn.__code__)
...  # Apply modifications to the bytecode
new_fn = assemble(instructions)

Context: I'm trying to run a function with closure on eval, which isn't supported. So I'm trying to replace those closure by globals.

rocky commented

See https://stackoverflow.com/questions/33348067/modifying-python-bytecode/40105522#40105522

StackOverflow seems like a better kind of place for this kind of discussion.

Thanks. The documentation wasn't clear, which is why I posted here.

I ended up using pip install bytecode instead.