2008-07-15: Selected articles (including this one) now have experimental "comment" links in the left column and at the bottom. You're welcome to use them for commenting and voting on articles. For a bit more on this, see this page. /F

The dis module

This is the Python disassembler. It converts bytecodes to a format that is slightly more appropriate for human consumption.

You can run the disassembler from the command line. It compiles the given script, and prints the disassembled byte codes to the terminal.

 
$ dis.py hello.py

          0 SET_LINENO       0

          3 SET_LINENO       1
          6 LOAD_CONST       0 ('hello again, and welcome to the show')
          9 PRINT_ITEM
         10 PRINT_NEWLINE
         11 LOAD_CONST       1 (None)
         14 RETURN_VALUE

You can also use dis as a module. The dis function takes a class, method, function, or code object as its single argument.

Example: Using the dis module
# File: dis-example-1.py

import dis

def procedure():
    print 'hello'

dis.dis(procedure)

          0 SET_LINENO          3

          3 SET_LINENO          4
          6 LOAD_CONST          1 ('hello')
          9 PRINT_ITEM
         10 PRINT_NEWLINE
         11 LOAD_CONST          0 (None)
         14 RETURN_VALUE
 
[comment on/vote for this article]

A Django site. this page was rendered by a django application in 0.02s 2008-07-25 10:12:51.392858. hosted by webfaction.