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()
 

[comment on/vote for this article]

A Django site. this page was rendered by a django application in 0.01s 2008-08-29 23:21:08.049559. hosted by webfaction.