The dis Module

The dis module is the Python disassembler. It converts byte codes 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 11-1 uses the module.

Example 11-1. 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

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net