We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

The codecs Module

(New in 2.0) The codecs module provides an interface to the Python codec registry, which holds converters used by the encode and decode string methods.

The module also contains a number of helper functions and classes, including codecs.open which opens an encoded stream. All data read from the file will be decoded as necessary, and data written to an encoded stream will be encoded.

# File: codecs-example-1.py

import codecs

f = codecs.open("sample.txt", "r", "iso-8859-1")

print repr(f.readline())

f.close()