[Python-Dev] Status of the PEP 400? (deprecate codecs.StreamReader/StreamWriter)

Victor Stinner victor.stinner at haypocalc.com
Thu Jul 28 10:49:33 CEST 2011


Le 28/07/2011 06:10, Benjamin Peterson a écrit :
>>>> there any reason to continue using codecs.open()?
>>>
>>> It's the easiest way to write Unicode friendly code that spans both 2.x and 3.x.
>>
>> Even on 2.6, where the io module exists?
>
> io on 2.6 is fairly broken and dead slow. The advantage of codecs.open
> is it hasn't changed in the very long time. It still has the same
> reliable buggy behavior no matter what version you're on.
>
> I don't see the problem with leaving codecs.open() to rot a few more
> releases before deprecating it while leaving messaging in the docs
> suggesting io.*.

All these points were already discussed before.

There is a subsection in "Backwards Compatibility" section in the PEP 
400 explaining why codecs.open is NOT deprecated:

http://www.python.org/dev/peps/pep-0400/#keep-the-public-api-codecs-open

"codecs.open() can be replaced by the builtin open() function. open() 
has a similar API but has also more options. Both functions return 
file-like objects (same API).

codecs.open() was the only way to open a text file in Unicode mode until 
Python 2.6. Many Python 2 programs uses this function. Removing 
codecs.open() implies more work to port programs from Python 2 to Python 
3, especially projets using the same code base for the two Python 
versions (without using 2to3 program).

codecs.open() is kept for backward compatibility with Python 2."

Victor


More information about the Python-Dev mailing list