print dos format file into unix format

Steve Holden steve at holdenweb.com
Sat Oct 21 19:46:19 EDT 2006


PengYu.UT at gmail.com wrote:
> Suppose I have a dos format text file. The following python code will
> print ^M at the end. I'm wondering how to print it in unix format.
> 
> fh = open(options.filename)
> for line in fh.readlines()
>   print line,
> 
> Thanks,
> Peng
> 
open(outfile, "wb").write(open(infile, "rb").read().replace("\r", ""))

Or something like that ... :)

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list