File: docstrings.html

package info (click to toggle)
epydoc 2.1-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,364 kB
  • ctags: 2,878
  • sloc: python: 9,010; makefile: 85; sh: 73
file content (83 lines) | stat: -rw-r--r-- 3,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Python Docstrings</title>
<link rel="stylesheet" href="epydoc.css" type="text/css"/>
</head>
<!-- $Id: docstrings.html,v 1.5 2002/10/02 07:07:08 edloper Exp $ -->
<body>

<h1> Python Docstrings </h1>

<p> Python documentation strings (or <i>docstrings</i>) provide a
convenient way of associating documentation with Python modules,
functions, classes, and methods.  An object's docsting is defined by
including a string constant as the first statement in the object's
definition.  For example, the following function defines a docstring:
</p>

<div class="screen"><pre>
<code class="keyword">def</code> <code class="function">x_intercept</code>(m, b):
    <code class="string">"""
    Return the x intercept of the line y=m*x+b.  The x intercept of a
    line is the point at which it crosses the x axis (y=0).
    """</code>
    <code class="keyword">return</code> -b/m
</pre></div>

<p> Docstrings can be accessed from the interpreter and from Python
programs using the "<code>__doc__</code>" attribute: </p>

<div class="screen"><pre>
<code class="prompt">&gt;&gt;&gt;</code> <code class="user"><code class="keyword">print</code> x_intercept.__doc__</code><code class="output">
    Return the x intercept of the line y=m*x+b.  The x intercept of a
    line is the point at which it crosses the x axis (y=0).</code>
</pre></div>

<p> The <a href="http://web.lfw.org/python/pydoc.html">pydoc</a>
module, which became part of <a
href="http://www.python.org/doc/current/lib/module-pydoc.html">
the standard library</a> in Python 2.1, can be used to display
information about a Python object, including its docstring: </p>

<div class="screen"><pre>
<code class="prompt">&gt;&gt;&gt;</code> <code class="user"><code class="keyword">from</code> pydoc <code class="keyword">import</code> help</code>

<code class="prompt">&gt;&gt;&gt;</code> <code class="user">help(x_intercept)</code>
<code class="output">Help on function x_intercept in module __main__:

<b>x_intercept</b>(m, b)
    Return the x intercept of the line y=m*x+b.  The x intercept of a
    line is the point at which it crosses the x axis (y=0).</code>
</pre></div>

<p> For more information about Python docstrings, see the <a
href="http://www.python.org/doc/current/tut/node6.html#SECTION006750000000000000000">Python
Tutorial</a> or the Oreilly Network article <a
href="http://www.onlamp.com/lpt/a/python/2001/05/17/docstrings.html">Python
Documentation Tips and Tricks</a>. </p>

<table width="100%" class="navbox" cellpadding="1" cellspacing="0">
  <tr>
  <td align="center" width="16.6%">
    <a class="nav" href="index.html">[Epydoc]</a></td>
  <td align="center" width="16.6%">
    <a class="nav" href="installing.html">[Installing]</a></td>
  <td align="center" width="16.6%">
    <a class="nav" href="using.html">[Using]</a></td>
  <td align="center" width="16.6%">
    <a class="nav" href="epytext.html">[Epytext]</a></td>
  <td align="center" width="16.6%">
    <a class="nav" href="http://www.cis.upenn.edu/~edloper/">[Author]</a></td>
  <td align="center" width="16.6%">
    <A href="http://sourceforge.net/projects/epydoc"> 
    <IMG src="sflogo.png" 
    width="88" height="26" border="0" alt="SourceForge"
    align="top"/></A></td>
    </tr>
</table>

<font size="-1">
<!-- hhmts start --> Last modified: Wed Sep 25 16:48:48 EDT 2002 <!-- hhmts end -->
</font>
</body>
</html>