What is the correct way to port codecs.open to python 3.1?

Baptiste Lepilleur baptiste.lepilleur at gmail.com
Sat Nov 7 09:41:01 EST 2009


2009/11/7 MRAB <python at mrabarnett.plus.com>

> Baptiste Lepilleur wrote:
>
 [..]
>> Do I need to replace all codecs.open with the built-in open function? If
>> so, why does codecs.open still exist?
>>
>>  The documentation says of codecs.open() that "Files are always opened in
> binary mode, even if no binary mode was specified", but you've given the
> mode as 'rt', so you're asking it to open the file both in text mode
> _and_ binary mode. This is the same as in Python 2.6.
>
> If it works in 2.6 but not in 3.1, perhaps it's just that in 2.6 it
> ignores the 't' whereas in 3.1 it complains.
>

So I did miss something, but it was in 2.6. Thanks for the clarification.

Though, I think the documentation is somewhat confusing in 3.x as it says
that it opens the file in binary mode, but the opened file iterator returns
str not bytes...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091107/f2316934/attachment-0001.html>


More information about the Python-list mailing list