When to use codecs vs. io module (Python 2.7 and higher)

Antoine Pitrou solipsis at pitrou.net
Wed Dec 1 10:06:53 EST 2010


On Wed, 01 Dec 2010 09:55:01 -0500
python at bdurham.com wrote:
> Python 2.7 or higher: Looking for reasons/scenarios where one
> should use the codecs vs. io module.
> 
> Are there use cases that favor one specific module over the other
> module?
> 
> My understanding is that the io module is much faster than the
> codecs module (and can be used interchangably), but the codecs
> module provides backward compatibility if you need to target
> versions of Python less than 2.6.

That's a good summary, although I'm not sure codecs and io are
interchangeable. They will certainly have slightly different behaviour
in corner cases. The io module is much more tested since it's the
official way to do I/O in Python 3, so its own corner cases are
probably better than those in the codecs module :)

Regards

Antoine.





More information about the Python-list mailing list