Removing ^M

Michael Hall olc at ninti.com
Sat Jun 8 21:27:56 EDT 2002


Python ... I love it! I knew about dos2unix but it's not on my box for
some reason, and downloading and installing it seemed like overkill.
This script worked like a charm.

Thanks 
Mick



On Sat, 8 Jun 2002, Chris Gonnerman wrote:

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

-- 
--------------------------------
n   i   n   t   i  .   c   o   m
php-python-perl-mysql-postgresql
--------------------------------
Michael Hall     ninti at ninti.com
--------------------------------







More information about the Python-list mailing list