Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:3.7 UserDictUp:3. Python Runtime ServicesNext:3.9 UserString

3.8UserList -- Class wrapper for list objects

Note:This module is available for backward compatibility only. Ifyou are writing code that does not need to work with versions ofPython earlier than Python 2.2, please consider subclassing directlyfrom the built-inlist type.

This module defines a class that acts as a wrapper aroundlist objects. It is a useful base class foryour own list-like classes, which can inherit fromthem and override existing methods or add new ones. In this way onecan add new behaviors to lists.

TheUserList module defines theUserList class:

classUserList([list])
Class that simulates a list. The instance'scontents are kept in a regular list, which is accessible via thedata attribute ofUserList instances. The instance'scontents are initially set to a copy oflist, defaulting to theempty list[].list can be either a regular Python list,or an instance ofUserList (or a subclass).

In addition to supporting the methods and operations of mutablesequences (see section2.2.6),UserList instancesprovide the following attribute:

data
A real Python list object used to store the contents of theUserList class.

Subclassing requirements:Subclasses ofUserList are expect to offer a constructor whichcan be called with either no arguments or one argument. Listoperations which return a new sequence attempt to create an instanceof the actual implementation class. To do so, it assumes that theconstructor can be called with a single parameter, which is a sequenceobject used as a data source.

If a derived class does not wish to comply with this requirement, allof the special methods supported by this class will need to beoverridden; please consult the sources for information about themethods which need to be provided in that case.

Changed in version 2.0:Python versions 1.5.2 and 1.6 also required that the constructor be callable with no parameters, and offer a mutabledata attribute. Earlier versions of Python did not attempt to create instances of the derived class.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:3.7 UserDictUp:3. Python Runtime ServicesNext:3.9 UserString
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp