Best practice way to open files in Python 2.6+?

Brian Curtin brian.curtin at gmail.com
Tue Jul 27 11:09:28 EDT 2010


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

> Brian,
>
>  Under Python 2.6.4 (Windows), "io.open is open" returns False. Retrieving
> help() on io.open and open() reinforces that these are 2 different
> implementations of open.
>
> My use case is reading and writing UTF-8 text files with universal newline
> support. I believe that the following io.open() parameter list is what I
> should be using:
>
> # mode set to 'rt' (read) or 'wt' (write)
> io.open( file, mode, encoding='utf-8', errors='ignore', newline=None )
>
> Malcolm
>

Precisely. I was just showing that in 3.x they are the same because one uses
the other, and that reason might be enough for you to consider io.open.

Your usage of io.open looks fine to me. If it works for you, keep doing it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100727/77a19790/attachment.html>


More information about the Python-list mailing list