| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="inspect-classes-functions.html" /> |
| 13 | <link rel="prev" href="inspect-types.html" /> |
| 14 | <link rel="parent" href="module-inspect.html" /> |
| 15 | <link rel="next" href="inspect-classes-functions.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>3.11.2 Retrieving source code </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="3.11.1 Types and members" |
| 25 | href="inspect-types.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="3.11 inspect " |
| 28 | href="module-inspect.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="3.11.3 Classes and functions" |
| 31 | href="inspect-classes-functions.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="inspect-types.html">3.11.1 Types and members</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="inspect-classes-functions.html">3.11.3 Classes and functions</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0051120000000000000000"></A><A NAME="inspect-source"></A> |
| 56 | <BR> |
| 57 | 3.11.2 Retrieving source code |
| 58 | |
| 59 | </H2> |
| 60 | |
| 61 | <P> |
| 62 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 63 | <td><nobr><b><tt id='l2h-585' xml:id='l2h-585' class="function">getdoc</tt></b>(</nobr></td> |
| 64 | <td><var>object</var>)</td></tr></table></dt> |
| 65 | <dd> |
| 66 | Get the documentation string for an object. |
| 67 | All tabs are expanded to spaces. To clean up docstrings that are |
| 68 | indented to line up with blocks of code, any whitespace than can be |
| 69 | uniformly removed from the second line onwards is removed. |
| 70 | </dl> |
| 71 | |
| 72 | <P> |
| 73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 74 | <td><nobr><b><tt id='l2h-586' xml:id='l2h-586' class="function">getcomments</tt></b>(</nobr></td> |
| 75 | <td><var>object</var>)</td></tr></table></dt> |
| 76 | <dd> |
| 77 | Return in a single string any lines of comments immediately preceding |
| 78 | the object's source code (for a class, function, or method), or at the |
| 79 | top of the Python source file (if the object is a module). |
| 80 | </dl> |
| 81 | |
| 82 | <P> |
| 83 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 84 | <td><nobr><b><tt id='l2h-587' xml:id='l2h-587' class="function">getfile</tt></b>(</nobr></td> |
| 85 | <td><var>object</var>)</td></tr></table></dt> |
| 86 | <dd> |
| 87 | Return the name of the (text or binary) file in which an object was |
| 88 | defined. This will fail with a <tt class="exception">TypeError</tt> if the object |
| 89 | is a built-in module, class, or function. |
| 90 | </dl> |
| 91 | |
| 92 | <P> |
| 93 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 94 | <td><nobr><b><tt id='l2h-588' xml:id='l2h-588' class="function">getmodule</tt></b>(</nobr></td> |
| 95 | <td><var>object</var>)</td></tr></table></dt> |
| 96 | <dd> |
| 97 | Try to guess which module an object was defined in. |
| 98 | </dl> |
| 99 | |
| 100 | <P> |
| 101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 102 | <td><nobr><b><tt id='l2h-589' xml:id='l2h-589' class="function">getsourcefile</tt></b>(</nobr></td> |
| 103 | <td><var>object</var>)</td></tr></table></dt> |
| 104 | <dd> |
| 105 | Return the name of the Python source file in which an object was |
| 106 | defined. This will fail with a <tt class="exception">TypeError</tt> if the object |
| 107 | is a built-in module, class, or function. |
| 108 | </dl> |
| 109 | |
| 110 | <P> |
| 111 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 112 | <td><nobr><b><tt id='l2h-590' xml:id='l2h-590' class="function">getsourcelines</tt></b>(</nobr></td> |
| 113 | <td><var>object</var>)</td></tr></table></dt> |
| 114 | <dd> |
| 115 | Return a list of source lines and starting line number for an object. |
| 116 | The argument may be a module, class, method, function, traceback, frame, |
| 117 | or code object. The source code is returned as a list of the lines |
| 118 | corresponding to the object and the line number indicates where in the |
| 119 | original source file the first line of code was found. An |
| 120 | <tt class="exception">IOError</tt> is raised if the source code cannot be retrieved. |
| 121 | </dl> |
| 122 | |
| 123 | <P> |
| 124 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 125 | <td><nobr><b><tt id='l2h-591' xml:id='l2h-591' class="function">getsource</tt></b>(</nobr></td> |
| 126 | <td><var>object</var>)</td></tr></table></dt> |
| 127 | <dd> |
| 128 | Return the text of the source code for an object. |
| 129 | The argument may be a module, class, method, function, traceback, frame, |
| 130 | or code object. The source code is returned as a single string. An |
| 131 | <tt class="exception">IOError</tt> is raised if the source code cannot be retrieved. |
| 132 | </dl> |
| 133 | |
| 134 | <P> |
| 135 | |
| 136 | <DIV CLASS="navigation"> |
| 137 | <div class='online-navigation'> |
| 138 | <p></p><hr /> |
| 139 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 140 | <tr> |
| 141 | <td class='online-navigation'><a rel="prev" title="3.11.1 Types and members" |
| 142 | href="inspect-types.html"><img src='../icons/previous.png' |
| 143 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 144 | <td class='online-navigation'><a rel="parent" title="3.11 inspect " |
| 145 | href="module-inspect.html"><img src='../icons/up.png' |
| 146 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 147 | <td class='online-navigation'><a rel="next" title="3.11.3 Classes and functions" |
| 148 | href="inspect-classes-functions.html"><img src='../icons/next.png' |
| 149 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 150 | <td align="center" width="100%">Python Library Reference</td> |
| 151 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 152 | href="contents.html"><img src='../icons/contents.png' |
| 153 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 154 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 155 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 156 | <td class='online-navigation'><a rel="index" title="Index" |
| 157 | href="genindex.html"><img src='../icons/index.png' |
| 158 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 159 | </tr></table> |
| 160 | <div class='online-navigation'> |
| 161 | <b class="navlabel">Previous:</b> |
| 162 | <a class="sectref" rel="prev" href="inspect-types.html">3.11.1 Types and members</A> |
| 163 | <b class="navlabel">Up:</b> |
| 164 | <a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A> |
| 165 | <b class="navlabel">Next:</b> |
| 166 | <a class="sectref" rel="next" href="inspect-classes-functions.html">3.11.3 Classes and functions</A> |
| 167 | </div> |
| 168 | </div> |
| 169 | <hr /> |
| 170 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 171 | </DIV> |
| 172 | <!--End of Navigation Panel--> |
| 173 | <ADDRESS> |
| 174 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 175 | </ADDRESS> |
| 176 | </BODY> |
| 177 | </HTML> |