Removing ^M

Chris Gonnerman chris.gonnerman at
Sat Jun 8 10:45:53 EDT 2002

----- Original Message ----- 
From: "Michael Hall" <olc at>

> 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 =

for ch in data:
    if ch != "\r":


Run it like this:

    python <source.html >destination.html

Yeah, it could have a bunch more nice stuff...  This is the Q&D 

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

More information about the Python-list mailing list