Commit | Line | Data |
---|---|---|
920dae64 AT |
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="module-UserString.html" /> | |
13 | <link rel="prev" href="module-UserDict.html" /> | |
14 | <link rel="parent" href="python.html" /> | |
15 | <link rel="next" href="module-UserString.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>3.8 UserList -- Class wrapper for list objects</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.7 UserDict " | |
25 | href="module-UserDict.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. Python Runtime Services" | |
28 | href="python.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.9 UserString " | |
31 | href="module-UserString.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="module-UserDict.html">3.7 UserDict </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-UserString.html">3.9 UserString </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION005800000000000000000"> | |
56 | 3.8 <tt class="module">UserList</tt> -- | |
57 | Class wrapper for list objects</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-UserList"></A> | |
62 | ||
63 | <P> | |
64 | <span class="note"><b class="label">Note:</b> | |
65 | This module is available for backward compatibility only. If | |
66 | you are writing code that does not need to work with versions of | |
67 | Python earlier than Python 2.2, please consider subclassing directly | |
68 | from the built-in <tt class="class">list</tt> type.</span> | |
69 | ||
70 | <P> | |
71 | This module defines a class that acts as a wrapper around | |
72 | list objects. It is a useful base class for | |
73 | your own list-like classes, which can inherit from | |
74 | them and override existing methods or add new ones. In this way one | |
75 | can add new behaviors to lists. | |
76 | ||
77 | <P> | |
78 | The <tt class="module">UserList</tt> module defines the <tt class="class">UserList</tt> class: | |
79 | ||
80 | <P> | |
81 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
82 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-483' xml:id='l2h-483' class="class">UserList</tt></b>(</nobr></td> | |
83 | <td><var></var><big>[</big><var>list</var><big>]</big><var></var>)</td></tr></table></dt> | |
84 | <dd> | |
85 | Class that simulates a list. The instance's | |
86 | contents are kept in a regular list, which is accessible via the | |
87 | <tt class="member">data</tt> attribute of <tt class="class">UserList</tt> instances. The instance's | |
88 | contents are initially set to a copy of <var>list</var>, defaulting to the | |
89 | empty list <code>[]</code>. <var>list</var> can be either a regular Python list, | |
90 | or an instance of <tt class="class">UserList</tt> (or a subclass). | |
91 | </dl> | |
92 | ||
93 | <P> | |
94 | In addition to supporting the methods and operations of mutable | |
95 | sequences (see section <A href="typesseq.html#typesseq">2.3.6</A>), <tt class="class">UserList</tt> instances | |
96 | provide the following attribute: | |
97 | ||
98 | <P> | |
99 | <dl><dt><b><tt id='l2h-484' xml:id='l2h-484' class="member">data</tt></b></dt> | |
100 | <dd> | |
101 | A real Python list object used to store the contents of the | |
102 | <tt class="class">UserList</tt> class. | |
103 | </dl> | |
104 | ||
105 | <P> | |
106 | <strong>Subclassing requirements:</strong> | |
107 | Subclasses of <tt class="class">UserList</tt> are expect to offer a constructor which | |
108 | can be called with either no arguments or one argument. List | |
109 | operations which return a new sequence attempt to create an instance | |
110 | of the actual implementation class. To do so, it assumes that the | |
111 | constructor can be called with a single parameter, which is a sequence | |
112 | object used as a data source. | |
113 | ||
114 | <P> | |
115 | If a derived class does not wish to comply with this requirement, all | |
116 | of the special methods supported by this class will need to be | |
117 | overridden; please consult the sources for information about the | |
118 | methods which need to be provided in that case. | |
119 | ||
120 | <P> | |
121 | ||
122 | <span class="versionnote">Changed in version 2.0: | |
123 | Python versions 1.5.2 and 1.6 also required that the | |
124 | constructor be callable with no parameters, and offer | |
125 | a mutable <tt class="member">data</tt> attribute. Earlier versions | |
126 | of Python did not attempt to create instances of the | |
127 | derived class.</span> | |
128 | ||
129 | <P> | |
130 | ||
131 | <DIV CLASS="navigation"> | |
132 | <div class='online-navigation'> | |
133 | <p></p><hr /> | |
134 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
135 | <tr> | |
136 | <td class='online-navigation'><a rel="prev" title="3.7 UserDict " | |
137 | href="module-UserDict.html"><img src='../icons/previous.png' | |
138 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
139 | <td class='online-navigation'><a rel="parent" title="3. Python Runtime Services" | |
140 | href="python.html"><img src='../icons/up.png' | |
141 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
142 | <td class='online-navigation'><a rel="next" title="3.9 UserString " | |
143 | href="module-UserString.html"><img src='../icons/next.png' | |
144 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
145 | <td align="center" width="100%">Python Library Reference</td> | |
146 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
147 | href="contents.html"><img src='../icons/contents.png' | |
148 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
149 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
150 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
151 | <td class='online-navigation'><a rel="index" title="Index" | |
152 | href="genindex.html"><img src='../icons/index.png' | |
153 | border='0' height='32' alt='Index' width='32' /></A></td> | |
154 | </tr></table> | |
155 | <div class='online-navigation'> | |
156 | <b class="navlabel">Previous:</b> | |
157 | <a class="sectref" rel="prev" href="module-UserDict.html">3.7 UserDict </A> | |
158 | <b class="navlabel">Up:</b> | |
159 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> | |
160 | <b class="navlabel">Next:</b> | |
161 | <a class="sectref" rel="next" href="module-UserString.html">3.9 UserString </A> | |
162 | </div> | |
163 | </div> | |
164 | <hr /> | |
165 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
166 | </DIV> | |
167 | <!--End of Navigation Panel--> | |
168 | <ADDRESS> | |
169 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
170 | </ADDRESS> | |
171 | </BODY> | |
172 | </HTML> |