print dos format file into unix format

Simon Forman rogue_pedro at yahoo.com
Sun Oct 22 17:11:04 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

Python ships with two utility scripts, crlf.py and lfcr.py, that
"Replace CRLF with LF in argument files" and "Replace LF with CRLF in
argument files", respectively.

Look in examples/Tools/scripts of your python dist.

Even if you don't want to use the scripts, you can read them for
insight.

Peace,
~Simon




More information about the Python-list mailing list