Re: print dos format file into unix format
Tim Roberts wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] 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, Are you running this on Unix or on DOS? On Unix, you can do: for line in open(options.filename).readlines(): print line.rstrip() Perhaps quicker is: sys.stdout.write( open(options.filename).read().replace('\r\n','\n') ) There are more differences between text files than that. I don't know any unix systems that uses CP 437 etc. I'd convert the text to unicode through .decode('cp437') etc, and then print that. If things aren't set up so than unicode object print correctly, use .decode('cp437').encode('utf8') etc to get it to an appropriate encoding. -- http://mail.python.org/mailman/listinfo/python-list
Re: print dos format file into unix format
[EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list
print dos format file into unix format
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: print dos format file into unix format
[EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: print dos format file into unix format
[EMAIL PROTECTED] [EMAIL PROTECTED] 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, Are you running this on Unix or on DOS? On Unix, you can do: for line in open(options.filename).readlines(): print line.rstrip() Perhaps quicker is: sys.stdout.write( open(options.filename).read().replace('\r\n','\n') ) -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list