Best practice way to open files in Python 2.6+?

Brian Curtin brian.curtin at gmail.com
Tue Jul 27 10:54:08 EDT 2010


On Tue, Jul 27, 2010 at 09:33, <python at bdurham.com> wrote:

> What is the best practice way to open files in Python 2.6+
>
> It looks like there are at least 3 different ways to open files:
> - built-in open()
> - io.open()
> - codecs.open()
>
> It seems like io.open() combines the best of the built-in open() and the
> codecs open(). Am I missing any obvious drawbacks to using io.open() except
> for backwards compatibility?
>
> Thank you,
> Malcolm
>

As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also
3.0, don't know). I don't know your use cases or what you get or don't get
from any of those options, but the future is io.open.

>>> io.open is open
True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100727/d0debfde/attachment.html>


More information about the Python-list mailing list