Python is a hybrid interpreter. When running a program, it first assembles it into bytecode which can then be run in the Python interpreter (also called a Python virtual machine). The dis module in the standard library can be used to make the Python bytecode human-readable by disassembling classes, methods, functions, and code objects.
The Python interpreter is stack-based and uses a first-in last-out system.
Each operation code (opcode) in the Python assembly language (the bytecode) takes a fixed number of items from the stack and returns a fixed number of items to the stack. If there aren't enough items on the stack for an opcode, the Python interpreter will crash, possibly without an error message.
Constants in the dis module
To disassemble a Python module, first this has to be turned into a .pyc file (Python compiled). To do this, run
Then in an interpreter, run
This will compile a Python module and output the bytecode instructions with dis. The module is never imported so it is safe to use with untrusted code.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0