mac text files & for line

Humberto hypertaos at
Tue Jun 16 22:31:56 CEST 2009

On Jun 16, 1:39 pm, MRAB <pyt... at> wrote:
> Humberto wrote:
> > Greetings.
> > This is probably a v. basic question, but my apologies as I'm
> > relatively new w/ this.
> > 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.
> > Any help would be greatly appreciated and thanks!
> Open the file with mode 'U' for universal newline support ('\n', '\r' or
> '\r\n').

Precisely my problem. Thanks so much. I'd overlooked the references to
U in the entry for the open function.

To the other fellow, I think the question was reasonably specific in
the second paragraph...I sense the helpful response bore that out. I
certainly acknowledge my mistake in having overlooked the reference in
the documentation. So my apologies for any inconvenience and thanks

More information about the Python-list mailing list