mac text files & for line

Scott David Daniels Scott.Daniels at Acm.Org
Tue Jun 16 15:19:02 EDT 2009

MRAB wrote:
> Humberto wrote:
>> But I am attempting to use <i>for line</i> to iterate through a text
>> file, but I am working on a Mac and am getting a single block of text.
>> I assume this is because of the Mac {CR} usage vs. line feed.
>> Is there a programmatic way to use for line to interpret the carriage
>> return character as a new line? Otherwise, what are the easiest ways
>> to be able to force a replacement of the {CR} character w/ the line
>> feed? I've attempted the method using <i>tr</i>, but receive an
>> illegal byte sequence error when running the tr '\r' '\n' < file1.txt
>>> file2.txt command on my Mac.

Show code, inputs, and output and explain what you expected.

This could be one of dozens of problems.

> Open the file with mode 'U' for universal newline support ('\n', '\r' or
> '\r\n').
A good guess of what might be going wrong.
Another could be using read.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list