If, for example, I want to view the bytecode for the function x:
def f(x):
print(x * 10)
I would use the dis
module, which would generate this:
>>> def f(x):
... print(x * 10)
...
>>> dis.dis(f)
2 0 LOAD_GLOBAL 0 (print)
2 LOAD_GLOBAL 1 (x)
4 LOAD_CONST 1 (10)
6 BINARY_MULTIPLY
8 CALL_FUNCTION 1
10 POP_TOP
12 LOAD_CONST 0 (None)
14 RETURN_VALUE
>>>
Yet, is there a way to view the actual code of the function? For example, the output would be:
def func1(var1):
const1 = 10
print(var1 * const1)