(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.
File: util-example-1.py def remove(sequence, item): if item in sequence: sequence.remove(item)
Example 14-22 shows how readfile(filename) => string reads the contents of a text file as a single string.
File: util-example-2.py def readfile(filename): file = open(filename, "r") return file.read()
Example 14-23 shows how readopenfile(file) => string returns the contents of an open file (or other file object).
File: util-example-3.py def readopenfile(file): return file.read()
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