blob: 1768f652abb99d6cffc48cb0bab32665673a5bbb [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{UserDict} ---
Fred Drake6bf37de1999-06-29 18:13:37 +00002 Class wrapper for dictionary objects}
3
Fred Drakeb91e9341998-07-23 17:59:49 +00004\declaremodule{standard}{UserDict}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Class wrapper for dictionary objects.}
6
Fred Drake1ce36041998-04-07 20:05:33 +00007This module defines a class that acts as a wrapper around
8dictionary objects. It is a useful base class for
9your own dictionary-like classes, which can inherit from
Guido van Rossum7f3b0421997-03-27 14:56:18 +000010them and override existing methods or add new ones. In this way one
Fred Drake1ce36041998-04-07 20:05:33 +000011can add new behaviours to dictionaries.
Guido van Rossum7f3b0421997-03-27 14:56:18 +000012
Fred Drake802a2021998-02-19 06:26:35 +000013The \module{UserDict} module defines the \class{UserDict} class:
Guido van Rossum7f3b0421997-03-27 14:56:18 +000014
Fred Drake8d212431999-07-26 15:45:52 +000015\begin{classdesc}{UserDict}{\optional{intialdata}}
Guido van Rossum7f3b0421997-03-27 14:56:18 +000016Return a class instance that simulates a dictionary. The instance's
17contents are kept in a regular dictionary, which is accessible via the
Fred Drake8d212431999-07-26 15:45:52 +000018\member{data} attribute of \class{UserDict} instances. If
19\var{initialdata} is provided, \member{data} is initialized with its
20contents; note that a reference to \var{initialdata} will not be kept,
21allowing it be used used for other purposes.
Fred Drake802a2021998-02-19 06:26:35 +000022\end{classdesc}
Guido van Rossum7f3b0421997-03-27 14:56:18 +000023
Fred Drake6bf37de1999-06-29 18:13:37 +000024In addition to supporting the methods and operations of mappings (see
25section \ref{typesmapping}), \class{UserDict} instances provide the
26following attribute:
27
Fred Drake1ce36041998-04-07 20:05:33 +000028\begin{memberdesc}{data}
29A real dictionary used to store the contents of the \class{UserDict}
30class.
31\end{memberdesc}
32
33
Fred Drake295da241998-08-10 19:42:37 +000034\section{\module{UserList} ---
Fred Drake6bf37de1999-06-29 18:13:37 +000035 Class wrapper for list objects}
Fred Drakeb91e9341998-07-23 17:59:49 +000036
Fred Drake6bf37de1999-06-29 18:13:37 +000037\declaremodule{standard}{UserList}
Fred Drakeb91e9341998-07-23 17:59:49 +000038\modulesynopsis{Class wrapper for list objects.}
39
Fred Drake1ce36041998-04-07 20:05:33 +000040
41This module defines a class that acts as a wrapper around
42list objects. It is a useful base class for
43your own list-like classes, which can inherit from
44them and override existing methods or add new ones. In this way one
45can add new behaviours to lists.
46
Fred Drake802a2021998-02-19 06:26:35 +000047The \module{UserList} module defines the \class{UserList} class:
Guido van Rossum7f3b0421997-03-27 14:56:18 +000048
Fred Drake802a2021998-02-19 06:26:35 +000049\begin{classdesc}{UserList}{\optional{list}}
Guido van Rossum7f3b0421997-03-27 14:56:18 +000050Return a class instance that simulates a list. The instance's
51contents are kept in a regular list, which is accessible via the
Fred Drake802a2021998-02-19 06:26:35 +000052\member{data} attribute of \class{UserList} instances. The instance's
Fred Drakefcda5601998-01-07 22:05:25 +000053contents are initially set to a copy of \var{list}, defaulting to the
Guido van Rossum7f3b0421997-03-27 14:56:18 +000054empty list \code{[]}. \var{list} can be either a regular Python list,
Fred Drake802a2021998-02-19 06:26:35 +000055or an instance of \class{UserList} (or a subclass).
56\end{classdesc}
Fred Drake1ce36041998-04-07 20:05:33 +000057
Fred Drake6bf37de1999-06-29 18:13:37 +000058In addition to supporting the methods and operations of mutable
59sequences (see section \ref{typesseq}), \class{UserList} instances
60provide the following attribute:
61
Fred Drake1ce36041998-04-07 20:05:33 +000062\begin{memberdesc}{data}
63A real Python list object used to store the contents of the
64\class{UserList} class.
65\end{memberdesc}
Fred Drakea22b5762000-04-03 03:51:50 +000066
67
68\section{\module{UserString} ---
69 Class wrapper for string objects}
70
71\declaremodule{standard}{UserString}
72\modulesynopsis{Class wrapper for string objects.}
73\moduleauthor{Peter Funk}{pf@artcom-gmbh.de}
74\sectionauthor{Peter Funk}{pf@artcom-gmbh.de}
75
76This module defines a class that acts as a wrapper around
77string objects. It is a useful base class for
78your own string-like classes, which can inherit from
79them and override existing methods or add new ones. In this way one
80can add new behaviours to strings.
81
82The \module{UserString} module defines the \class{UserString} class:
83
84\begin{classdesc}{UserString}{\optional{sequence}}
85Return a class instance that simulates a string or an unicode string object.
86The instance's content is kept in a regular string or unicode string
87object, which is accessible via the
88\member{data} attribute of \class{UserString} instances. The instance's
89contents are initially set to a copy of \var{sequence}.
90\var{sequence} can be either a regular Python string or unicode string,
91an instance of \class{UserString} (or a subclass) or an arbitrary sequence
92which can be converted into a string.
93supporting.
94\end{classdesc}
95
96In addition to supporting the methods and operations of string or
97unicode objects (see section \ref{typesseq}), \class{UserString} instances
98provide the following attribute:
99
100\begin{memberdesc}{data}
101A real Python string or unicode object used to store the content of the
102\class{UserString} class.
103\end{memberdesc}
104
105\begin{classdesc}{MutableString}{\optional{sequence}}
106This class is derived from the \class{UserString} above and redefines
107strings to be \emph{mutable}. Mutable strings can't be used as
108dictionary keys, because dictionaries require \emph{immutable} objects as
109keys. The main intention of this class is to serve as an educational
110example for inheritance and necessity to remove (override) the
111\function{__hash__} method in order to trap attempts to use a
112mutable object as dictionary key, which would be otherwise very
113errorprone and hard to track down.
114\end{classdesc}