The util Module

(Obsolete, Only in 1.5.2) The util module is included for backward-compatibility only. New code should use the replacement constructs shown in Examples 14-21 through 14-23.

Example 14-21 shows how remove(sequence, item) removes the given item, if found in the sequence.

Example 14-21. Emulating the util Modules remove Function

def remove(sequence, item):
 if item in sequence:

Example 14-22 shows how readfile(filename) => string reads the contents of a text file as a single string.

Example 14-22. Emulating the util Modules readfile Function

def readfile(filename):
 file = open(filename, "r")

Example 14-23 shows how readopenfile(file) => string returns the contents of an open file (or other file object).

Example 14-23. Emulating the util Modules readopenfile Function

def readopenfile(file):

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols


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 © 2008-2020.
If you may any questions please contact us: