Windows vs. file.read

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Fri Sep 3 04:25:31 CEST 2010


In message <mailman.379.1283444129.29448.python-list at python.org>, MRAB 
wrote:

> On 02/09/2010 08:49, Lawrence D'Oliveiro wrote:
>> In message<mailman.330.1283362312.29448.python-list at python.org>, MRAB
>> wrote:
>>
>>> You should open the files in binary mode, not text mode, ie file(path,
>>> "rb"). Text mode is the default. Not a problem on *nix because the line
>>> ending is newline.
>>
>> We used to pride ourselves on not having to worry about text versus
>> binary I/O modes on *nix, but I’m beginning to think the reality is we
>> have to adopt it.
>>
>> To start with, it means we can automatically handle different newline
>> conventions with text files originating on different systems.
> 
> In Python 3 the difference is important because binary mode works with
> bytes and text mode works with strings, plus the file encoding and line
> endings.

Yeah, that seems like a reasonable approach—make you decide up-front what 
exactly is the sort of file content you’re dealing with.



More information about the Python-list mailing list