Display the bytecode of a function

suggest change

The Python interpreter compiles code to bytecode before executing it on the Python’s virtual machine (see also http://stackoverflow.com/documentation/python/1763/the-dis-module/5729/what-is-python-bytecode#t=201609280954269606205).

Here’s how to view the bytecode of a Python function

import dis

def fib(n):
    if n <= 2: return 1
    return fib(n-1) + fib(n-2)

# Display the disassembled bytecode of the function.
dis.dis(fib)

The function dis.dis in the dis module will return a decompiled bytecode of the function passed to it.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents