Copyright (C) 2000-2012 |
GNU Info (python2.1-lib.info)UserStringClass wrapper for string objects ================================ Class wrapper for string objects. This module was written by Peter Funk <pf@artcom-gmbh.de>. This manual section was written by Peter Funk <pf@artcom-gmbh.de>. This module defines a class that acts as a wrapper around string objects. It is a useful base class for your own string-like classes, which can inherit from them and override existing methods or add new ones. In this way one can add new behaviors to strings. It should be noted that these classes are highly inefficient compared to real string or Unicode objects; this is especially the case for `MutableString'. The `UserString' module defines the following classes: `UserString([sequence])' Class that simulates a string or a Unicode string object. The instance's content is kept in a regular string or Unicode string object, which is accessible via the `data' attribute of `UserString' instances. The instance's contents are initially set to a copy of SEQUENCE. SEQUENCE can be either a regular Python string or Unicode string, an instance of `UserString' (or a subclass) or an arbitrary sequence which can be converted into a string using the built-in `str()' function. `MutableString([sequence])' This class is derived from the `UserString' above and redefines strings to be _mutable_. Mutable strings can't be used as dictionary keys, because dictionaries require _immutable_ objects as keys. The main intention of this class is to serve as an educational example for inheritance and necessity to remove (override) the `__hash__()' method in order to trap attempts to use a mutable object as dictionary key, which would be otherwise very error prone and hard to track down. In addition to supporting the methods and operations of string and Unicode objects (see section Note: String Methods, "String Methods"), `UserString' instances provide the following attribute: `data' A real Python string or Unicode object used to store the content of the `UserString' class. automatically generated by info2www version 1.2.2.9 |