Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 5 years ago.
Improve this question
Out of curiosity I would like to see the assembly instructions that correspond to the code of a .py file. Are there any trustworthy solutions you can propose?
The dis
module disassembles code objects (extracting those from functions, classes and objects with a __dict__
namespace).
This means you can use it to disassemble whole modules:
import dis
dis.dis(dis)
although this isn't nearly as interesting as you may think as most modules contain several functions and classes, leading to a lot of output.
I usually focus on smaller functions with specific aspects I am interested in; like what bytecode is generated for a chained comparison:
def f(x):
return 1 < x ** 2 < 100
dis.dis(f)
for example.