Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{UserDict} --- |
Fred Drake | 6bf37de | 1999-06-29 18:13:37 +0000 | [diff] [blame] | 2 | Class wrapper for dictionary objects} |
| 3 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{UserDict} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Class wrapper for dictionary objects.} |
| 6 | |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 7 | This module defines a class that acts as a wrapper around |
| 8 | dictionary objects. It is a useful base class for |
| 9 | your own dictionary-like classes, which can inherit from |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 10 | them and override existing methods or add new ones. In this way one |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 11 | can add new behaviors to dictionaries. |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 12 | |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 13 | The \module{UserDict} module defines the \class{UserDict} class: |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 14 | |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 15 | \begin{classdesc}{UserDict}{\optional{initialdata}} |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 16 | Return a class instance that simulates a dictionary. The instance's |
| 17 | contents are kept in a regular dictionary, which is accessible via the |
Fred Drake | 8d21243 | 1999-07-26 15:45:52 +0000 | [diff] [blame] | 18 | \member{data} attribute of \class{UserDict} instances. If |
| 19 | \var{initialdata} is provided, \member{data} is initialized with its |
| 20 | contents; note that a reference to \var{initialdata} will not be kept, |
| 21 | allowing it be used used for other purposes. |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 22 | \end{classdesc} |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 23 | |
Fred Drake | 6bf37de | 1999-06-29 18:13:37 +0000 | [diff] [blame] | 24 | In addition to supporting the methods and operations of mappings (see |
| 25 | section \ref{typesmapping}), \class{UserDict} instances provide the |
| 26 | following attribute: |
| 27 | |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 28 | \begin{memberdesc}{data} |
| 29 | A real dictionary used to store the contents of the \class{UserDict} |
| 30 | class. |
| 31 | \end{memberdesc} |
| 32 | |
| 33 | |
Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 34 | \section{\module{UserList} --- |
Fred Drake | 6bf37de | 1999-06-29 18:13:37 +0000 | [diff] [blame] | 35 | Class wrapper for list objects} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 36 | |
Fred Drake | 6bf37de | 1999-06-29 18:13:37 +0000 | [diff] [blame] | 37 | \declaremodule{standard}{UserList} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 38 | \modulesynopsis{Class wrapper for list objects.} |
| 39 | |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 40 | |
| 41 | This module defines a class that acts as a wrapper around |
| 42 | list objects. It is a useful base class for |
| 43 | your own list-like classes, which can inherit from |
| 44 | them and override existing methods or add new ones. In this way one |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 45 | can add new behaviors to lists. |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 46 | |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 47 | The \module{UserList} module defines the \class{UserList} class: |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 48 | |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 49 | \begin{classdesc}{UserList}{\optional{list}} |
Guido van Rossum | 7f3b042 | 1997-03-27 14:56:18 +0000 | [diff] [blame] | 50 | Return a class instance that simulates a list. The instance's |
| 51 | contents are kept in a regular list, which is accessible via the |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 52 | \member{data} attribute of \class{UserList} instances. The instance's |
Fred Drake | fcda560 | 1998-01-07 22:05:25 +0000 | [diff] [blame] | 53 | 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] | 54 | empty list \code{[]}. \var{list} can be either a regular Python list, |
Fred Drake | 802a202 | 1998-02-19 06:26:35 +0000 | [diff] [blame] | 55 | or an instance of \class{UserList} (or a subclass). |
| 56 | \end{classdesc} |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 57 | |
Fred Drake | 6bf37de | 1999-06-29 18:13:37 +0000 | [diff] [blame] | 58 | In addition to supporting the methods and operations of mutable |
| 59 | sequences (see section \ref{typesseq}), \class{UserList} instances |
| 60 | provide the following attribute: |
| 61 | |
Fred Drake | 1ce3604 | 1998-04-07 20:05:33 +0000 | [diff] [blame] | 62 | \begin{memberdesc}{data} |
| 63 | A real Python list object used to store the contents of the |
| 64 | \class{UserList} class. |
| 65 | \end{memberdesc} |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 66 | |
| 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 | |
| 76 | This module defines a class that acts as a wrapper around |
| 77 | string objects. It is a useful base class for |
| 78 | your own string-like classes, which can inherit from |
| 79 | them and override existing methods or add new ones. In this way one |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 80 | can add new behaviors to strings. |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 81 | |
| 82 | The \module{UserString} module defines the \class{UserString} class: |
| 83 | |
| 84 | \begin{classdesc}{UserString}{\optional{sequence}} |
Fred Drake | 6a0d844 | 2000-04-03 15:02:35 +0000 | [diff] [blame] | 85 | Return a class instance that simulates a string or a Unicode string object. |
| 86 | The instance's content is kept in a regular string or Unicode string |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 87 | object, which is accessible via the |
| 88 | \member{data} attribute of \class{UserString} instances. The instance's |
| 89 | contents are initially set to a copy of \var{sequence}. |
Fred Drake | 6a0d844 | 2000-04-03 15:02:35 +0000 | [diff] [blame] | 90 | \var{sequence} can be either a regular Python string or Unicode string, |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 91 | an instance of \class{UserString} (or a subclass) or an arbitrary sequence |
| 92 | which can be converted into a string. |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 93 | \end{classdesc} |
| 94 | |
| 95 | In addition to supporting the methods and operations of string or |
Fred Drake | 6a0d844 | 2000-04-03 15:02:35 +0000 | [diff] [blame] | 96 | Unicode objects (see section \ref{typesseq}), \class{UserString} instances |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 97 | provide the following attribute: |
| 98 | |
| 99 | \begin{memberdesc}{data} |
Fred Drake | 6a0d844 | 2000-04-03 15:02:35 +0000 | [diff] [blame] | 100 | A real Python string or Unicode object used to store the content of the |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 101 | \class{UserString} class. |
| 102 | \end{memberdesc} |
| 103 | |
| 104 | \begin{classdesc}{MutableString}{\optional{sequence}} |
| 105 | This class is derived from the \class{UserString} above and redefines |
| 106 | strings to be \emph{mutable}. Mutable strings can't be used as |
| 107 | dictionary keys, because dictionaries require \emph{immutable} objects as |
| 108 | keys. The main intention of this class is to serve as an educational |
| 109 | example for inheritance and necessity to remove (override) the |
| 110 | \function{__hash__} method in order to trap attempts to use a |
| 111 | mutable object as dictionary key, which would be otherwise very |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 112 | error prone and hard to track down. |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 113 | \end{classdesc} |