bytecode
bytecode copied to clipboard
Modify Existing bytecode
The documentation says that
bytecode is a Python module to ... modify bytecode.
What I would like to do is to modify existing bytecode.
Load a file, read the bytecode, modify it, save it out.
Can I do that with this package? Is this package only for creating code?
In #123 you can find a suggestion about how to read a pyc file https://github.com/MatthieuDartiailh/bytecode/issues/123. The part of writing it out is in https://github.com/P403n1x87/spasmlang/blob/d868ce2557e17fc3dd5a71fc7b155f3250a3aeb5/spasm/main.py#L23
The reference given by @P403n1x87 is likely to be the best. Other usage of bytecode I am aware of tend to work mostly in memory or at least retrieve code from live objects.