CPython allows access to the code object for a function object.
The __code__
object contains the raw bytecode (co_code
) of the function as well as other information such as constants and variable names.
def fib(n):
if n <= 2: return 1
return fib(n-1) + fib(n-2)
dir(fib.__code__)
def fib(n):
if n <= 2: return 1
return fib(n-1) + fib(n-2)
dir(fib.__code__)