Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 1 | \section{Standard Modules \sectcode{UserDict} and \sectcode{UserList}} |
Guido van Rossum | 692b87d | 1998-02-11 23:00:08 +0000 | [diff] [blame^] | 2 | \nodename{UserDict and UserList} |
Fred Drake | fcda560 | 1998-01-07 22:05:25 +0000 | [diff] [blame] | 3 | \stmodindex{UserDict} |
Guido van Rossum | 692b87d | 1998-02-11 23:00:08 +0000 | [diff] [blame^] | 4 | \stmodindex{UserList} |
Fred Drake | fcda560 | 1998-01-07 22:05:25 +0000 | [diff] [blame] | 5 | \label{module-UserDict} |
| 6 | \label{module-UserList} |
| 7 | |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 8 | Each of these modules defines a class that acts as a wrapper around |
| 9 | either dictionary or list objects. They're useful base classes for |
| 10 | your own dictionary-like or list-like classes, which can inherit from |
| 11 | them and override existing methods or add new ones. In this way one |
| 12 | can add new behaviours to dictionaries or lists. |
| 13 | |
| 14 | \renewcommand{\indexsubitem}{(in module UserDict)} |
| 15 | The \code{UserDict} module defines the \code{UserDict} class: |
| 16 | |
| 17 | \begin{funcdesc}{UserDict}{} |
| 18 | Return a class instance that simulates a dictionary. The instance's |
| 19 | contents are kept in a regular dictionary, which is accessible via the |
| 20 | \code{data} attribute of \code{UserDict} instances. |
| 21 | \end{funcdesc} |
| 22 | |
Fred Drake | fcda560 | 1998-01-07 22:05:25 +0000 | [diff] [blame] | 23 | \stmodindex{UserList} |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 24 | \renewcommand{\indexsubitem}{(in module UserList)} |
| 25 | The \code{UserList} module defines the \code{UserList} class: |
| 26 | |
| 27 | \begin{funcdesc}{UserList}{\optional{list}} |
| 28 | Return a class instance that simulates a list. The instance's |
| 29 | contents are kept in a regular list, which is accessible via the |
| 30 | \code{data} attribute of \code{UserList} instances. The instance's |
Fred Drake | fcda560 | 1998-01-07 22:05:25 +0000 | [diff] [blame] | 31 | contents are initially set to a copy of \var{list}, defaulting to the |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 32 | empty list \code{[]}. \var{list} can be either a regular Python list, |
| 33 | or an instance of \code{UserList} (or a subclass). |
| 34 | \end{funcdesc} |