blob: 51b7f5573f5f24220365d012dd5d473f4ad21d7a [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
Thomas Woutersf8316632000-07-16 19:01:10 +000011can add new behaviors 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
Thomas Woutersf8316632000-07-16 19:01:10 +000015\begin{classdesc}{UserDict}{\optional{initialdata}}
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
Thomas Woutersf8316632000-07-16 19:01:10 +000045can add new behaviors to lists.
Fred Drake1ce36041998-04-07 20:05:33 +000046
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
Thomas Woutersf8316632000-07-16 19:01:10 +000080can add new behaviors to strings.
Fred Drakea22b5762000-04-03 03:51:50 +000081
82The \module{UserString} module defines the \class{UserString} class:
83
84\begin{classdesc}{UserString}{\optional{sequence}}
Fred Drake6a0d8442000-04-03 15:02:35 +000085Return a class instance that simulates a string or a Unicode string object.
86The instance's content is kept in a regular string or Unicode string
Fred Drakea22b5762000-04-03 03:51:50 +000087object, 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}.
Fred Drake6a0d8442000-04-03 15:02:35 +000090\var{sequence} can be either a regular Python string or Unicode string,
Fred Drakea22b5762000-04-03 03:51:50 +000091an instance of \class{UserString} (or a subclass) or an arbitrary sequence
92which can be converted into a string.
Fred Drakea22b5762000-04-03 03:51:50 +000093\end{classdesc}
94
95In addition to supporting the methods and operations of string or
Fred Drake6a0d8442000-04-03 15:02:35 +000096Unicode objects (see section \ref{typesseq}), \class{UserString} instances
Fred Drakea22b5762000-04-03 03:51:50 +000097provide the following attribute:
98
99\begin{memberdesc}{data}
Fred Drake6a0d8442000-04-03 15:02:35 +0000100A real Python string or Unicode object used to store the content of the
Fred Drakea22b5762000-04-03 03:51:50 +0000101\class{UserString} class.
102\end{memberdesc}
103
104\begin{classdesc}{MutableString}{\optional{sequence}}
105This class is derived from the \class{UserString} above and redefines
106strings to be \emph{mutable}. Mutable strings can't be used as
107dictionary keys, because dictionaries require \emph{immutable} objects as
108keys. The main intention of this class is to serve as an educational
109example for inheritance and necessity to remove (override) the
110\function{__hash__} method in order to trap attempts to use a
111mutable object as dictionary key, which would be otherwise very
Thomas Woutersf8316632000-07-16 19:01:10 +0000112error prone and hard to track down.
Fred Drakea22b5762000-04-03 03:51:50 +0000113\end{classdesc}