Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disassemble a Python script?

Earlier today, I asked a question about the way Python handles certain kinds of loops. One of the answers contained disassembled versions of my examples.

I'd like to know more. How can I disassemble my own Python code?

like image 889
A. Dorton Avatar asked May 15 '09 16:05

A. Dorton


1 Answers

Look at the dis module:

def myfunc(alist):
    return len(alist)

>>> dis.dis(myfunc)
  2           0 LOAD_GLOBAL              0 (len)
              3 LOAD_FAST                0 (alist)
              6 CALL_FUNCTION            1
              9 RETURN_VALUE
like image 143
Jason Baker Avatar answered Sep 18 '22 20:09

Jason Baker