The UserList Module

The UserList module contains a list class that can be subclassed (simply a Python wrapper for the built-in list type).

In Example 2-16, AutoList instances work just like ordinary lists, except that they allow you to insert items at the end by assigning to them.

Example 2-16. Using the UserList Module

File: userlist-example-1.py

import UserList

class AutoList(UserList.UserList):

 def _ _setitem_ _(self, i, item):
 if i == len(self.data):
 self.data.append(item)
 else:
 self.data[i] = item

list = AutoList()

for i in range(10):
 list[i] = i

print list

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net