[Tutor] deleting CR within files

David Talaga dtalaga at novodynamics.com
Sat Apr 17 12:41:43 EDT 2004

Closer Roger,
But I noticed that it is taking off 2 character (obviously -2) from the last
and not touching the <cr>'s.  hrmmm. How would I get rid of those pesky

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
Behalf Of Roger Merchberger
Sent: Saturday, April 17, 2004 12:26 PM
To: tutor at python.org
Subject: RE: [Tutor] deleting CR within files

Rumor has it that David Talaga may have mentioned these words:

>       out_file.write(i[:-1] + '\n') #maybe the problem is here?

If this is on a windows platform, you'll want this:

out_file.write(i[:-2] + '\n')

For the more popular computers/OSs, this is what the line endings are:

Linux: \n only
MS-DOS / Winders: \r\n
MacOS (at least thru ver.9): \r only

So you need to lop off the last 2 characters of the string on Winders and
replace with a single \n for *nix machines; Your current code on Winders is
only replacing the last \n with a \n, which isn't quite what you want. ;-)

Roger "Merch" Merchberger

Roger "Merch" Merchberger -- sysadmin, Iceberg Computers
zmerch at 30below.com

What do you do when Life gives you lemons,
and you don't *like* lemonade?????????????

Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list