📄 module-dis.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>17.10 dis -- Disassembler for Python byte code</title>
<META NAME="description" CONTENT="17.10 dis -- Disassembler for Python byte code">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="module-compileall.html" tppabs="http://www.python.org/doc/current/lib/module-compileall.html">
<LINK REL="up" href="language.html" tppabs="http://www.python.org/doc/current/lib/language.html">
<LINK REL="next" href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-compileall.html" tppabs="http://www.python.org/doc/current/lib/module-compileall.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="language.html" tppabs="http://www.python.org/doc/current/lib/language.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-compileall.html" tppabs="http://www.python.org/doc/current/lib/module-compileall.html">17.9 compileall </A>
<b class="navlabel">Up:</b> <a class="sectref" href="language.html" tppabs="http://www.python.org/doc/current/lib/language.html">17. Python Language Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html">17.10.1 Python Byte Code</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00191000000000000000000">
17.10 <tt class="module">dis</tt> --
Disassembler for Python byte code</A>
</H1>
<P>
<P>
The <tt class="module">dis</tt> module supports the analysis of Python byte code by
disassembling it. Since there is no Python assembler, this module
defines the Python assembly language. The Python byte code which
this module takes as an input is defined in the file
<span class="file">Include/opcode.h</span> and used by the compiler and the interpreter.
<P>
Example: Given the function <tt class="function">myfunc</tt>:
<P>
<dl><dd><pre class="verbatim">
def myfunc(alist):
return len(alist)
</pre></dl>
<P>
the following command can be used to get the disassembly of
<tt class="function">myfunc()</tt>:
<P>
<dl><dd><pre class="verbatim">
>>> dis.dis(myfunc)
0 SET_LINENO 1
3 SET_LINENO 2
6 LOAD_GLOBAL 0 (len)
9 LOAD_FAST 0 (alist)
12 CALL_FUNCTION 1
15 RETURN_VALUE
16 LOAD_CONST 0 (None)
19 RETURN_VALUE
</pre></dl>
<P>
The <tt class="module">dis</tt> module defines the following functions and constants:
<P>
<dl><dt><b><a name='l2h-3065'><tt class='function'>dis</tt></a></b> (<big>[</big><var>bytesource</var><big>]</big>)
<dd>
Disassemble the <var>bytesource</var> object. <var>bytesource</var> can denote
either a class, a method, a function, or a code object. For a class,
it disassembles all methods. For a single code sequence, it prints
one line per byte code instruction. If no object is provided, it
disassembles the last traceback.
</dl>
<P>
<dl><dt><b><a name='l2h-3066'><tt class='function'>distb</tt></a></b> (<big>[</big><var>tb</var><big>]</big>)
<dd>
Disassembles the top-of-stack function of a traceback, using the last
traceback if none was passed. The instruction causing the exception
is indicated.
</dl>
<P>
<dl><dt><b><a name='l2h-3067'><tt class='function'>disassemble</tt></a></b> (<var>code</var><big>[</big><var>, lasti</var><big>]</big>)
<dd>
Disassembles a code object, indicating the last instruction if <var>lasti</var>
was provided. The output is divided in the following columns:
<P>
<OL>
<LI>the current instruction, indicated as "<tt class="samp">-></tt>",
</LI>
<LI>a labelled instruction, indicated with "<tt class="samp">»</tt>",
</LI>
<LI>the address of the instruction,
</LI>
<LI>the operation code name,
</LI>
<LI>operation parameters, and
</LI>
<LI>interpretation of the parameters in parentheses.
</LI>
</OL>
<P>
The parameter interpretation recognizes local and global
variable names, constant values, branch targets, and compare
operators.
</dl>
<P>
<dl><dt><b><a name='l2h-3068'><tt class='function'>disco</tt></a></b> (<var>code</var><big>[</big><var>, lasti</var><big>]</big>)
<dd>
A synonym for disassemble. It is more convenient to type, and kept
for compatibility with earlier Python releases.
</dl>
<P>
<dl><dt><b><a name='l2h-3069'><tt>opname</tt></a></b>
<dd>
Sequence of operation names, indexable using the byte code.
</dl>
<P>
<dl><dt><b><a name='l2h-3070'><tt>cmp_op</tt></a></b>
<dd>
Sequence of all compare operation names.
</dl>
<P>
<dl><dt><b><a name='l2h-3071'><tt>hasconst</tt></a></b>
<dd>
Sequence of byte codes that have a constant parameter.
</dl>
<P>
<dl><dt><b><a name='l2h-3072'><tt>hasname</tt></a></b>
<dd>
Sequence of byte codes that access an attribute by name.
</dl>
<P>
<dl><dt><b><a name='l2h-3073'><tt>hasjrel</tt></a></b>
<dd>
Sequence of byte codes that have a relative jump target.
</dl>
<P>
<dl><dt><b><a name='l2h-3074'><tt>hasjabs</tt></a></b>
<dd>
Sequence of byte codes that have an absolute jump target.
</dl>
<P>
<dl><dt><b><a name='l2h-3075'><tt>haslocal</tt></a></b>
<dd>
Sequence of byte codes that access a local variable.
</dl>
<P>
<dl><dt><b><a name='l2h-3076'><tt>hascompare</tt></a></b>
<dd>
Sequence of byte codes of boolean operations.
</dl>
<P>
<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html5565"
href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html">17.10.1 Python Byte Code Instructions</A>
</UL>
<!--End of Table of Child-Links-->
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-compileall.html" tppabs="http://www.python.org/doc/current/lib/module-compileall.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="language.html" tppabs="http://www.python.org/doc/current/lib/language.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-compileall.html" tppabs="http://www.python.org/doc/current/lib/module-compileall.html">17.9 compileall </A>
<b class="navlabel">Up:</b> <a class="sectref" href="language.html" tppabs="http://www.python.org/doc/current/lib/language.html">17. Python Language Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="bytecodes.html" tppabs="http://www.python.org/doc/current/lib/bytecodes.html">17.10.1 Python Byte Code</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -