Tool for editing .pyc
files and Python bytecode in runtime.
"Some code":
def f():
print('Hello World')
Editing this "some code"
import random
import pyceditor
pyc = pyceditor.PycFile.load_from_pycode(f.__code__)
x = random.randint(15, 10**4)
pyc.code.co_consts = (None, 'Hi! Random number: %d' % x)
eval(pyc.pycode)
# prints random number