Removing ^M
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Sat Jun 8 10:45:53 EDT 2002
----- Original Message -----
From: "Michael Hall" <olc at ninti.com>
> I am trying remove ^M characters (some kind of newline character) from an
> HTML file. I've tried all sorts of string.replace and sed possibilities
> but the
> things just won't go away. Does anyone have a way of removing such
> characters?
Unixoid OS, right?
------------------------------------
import sys
data = sys.stdin.read()
for ch in data:
if ch != "\r":
sys.stdout.write(ch)
------------------------------------
Run it like this:
python cleaner.py <source.html >destination.html
Yeah, it could have a bunch more nice stuff... This is the Q&D
version.
If the file is really large this won't be real efficient, but for
small files it's probably the best way.
Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net
More information about the Python-list
mailing list