[Python-3000] the right way to open text files in P3K?
Christian Heimes
lists at cheimes.de
Fri Dec 14 08:42:42 CET 2007
Mark Summerfield wrote:
> Hi,
>
> I was wondering if it is yet known what the right way to open text files
> in P3K will be?
>
> According to the docs the signature for open() is:
>
> open(filename[, mode[, bufsize]])
The docs must be outdated. open() accepts more arguments:
open(file, mode='r', buffering=None, encoding=None, errors=None,
newline=None, closefd=True)
> Is that going to stay the same and default to UTF-8 if "b" is not in the
> mode (or if no mode is specified) and bytes if "b" is present?
The new IO library is using UTF-8 as default encoding for text mode
unless a different encoding is given. The open() function and the IO
streams are much closer to the codecs package.
help(open) isn't very helpful in 3.0a2 and earlier. I fixed the doc
string shortly after the release. import io; help(io.open) gives you the
real open function. Please note that the IO library is mostly written in
Python, see Lib/io.py
Christian
More information about the Python-3000
mailing list