Re: stripping blanks

2006-05-02 Thread Edward Elliott
Scott David Daniels wrote: > A little better: > > f = open("test.dat") > for line in f: > printLine = line.rstrip("\n") > if printLine: > print printLine [sys.stdout.write(line) for line in open('test.dat') if line.rstrip('\n')] Where's my prize? What do

Re: stripping blanks

2006-05-02 Thread Scott David Daniels
seeker wrote: > Last suggestion I made was bad. Here is the new one. Hopefully thats > correct. > > f = open("test.dat") > for line in f: > printLine = line.rstrip("\n") > if not printLine: > continue > print printLine A little better: f = open("test.dat") fo

Re: stripping blanks

2006-05-02 Thread Fredrik Lundh
Fulvio wrote: > > printLine = line.rstrip("\n") > > I think that nobody considered if the text has (\r) or (\r\n) or (\n) at the > end of the line(s). if it's opened in text mode (the default), and is a text file, it will always have "\n" at the end of the line. -- http://mail.python.org/ma

Re: stripping blanks

2006-05-02 Thread Duncan Booth
Fulvio wrote: > Alle 17:06, martedì 02 maggio 2006, seeker ha scritto: >>      printLine = line.rstrip("\n") > > I think that nobody considered if the text has (\r) or (\r\n) or (\n) > at the end of the line(s). > You think wrongly. The suggested code opens the file in text mode so the line end

Re: stripping blanks

2006-05-02 Thread Fulvio
Alle 17:06, martedì 02 maggio 2006, seeker ha scritto: >      printLine = line.rstrip("\n") I think that nobody considered if the text has (\r) or (\r\n) or (\n) at the end of the line(s). -- http://mail.python.org/mailman/listinfo/python-list

Re: stripping blanks

2006-05-02 Thread seeker
[EMAIL PROTECTED] wrote: > hi > i have a file test.dat eg > > abcdefgh > ijklmn > <-newline > opqrs > tuvwxyz > <---newline > > I wish to print the contents of the file such that it appears: > abcdefgh > ijklmn > opqrs > tuvwxyz > > here is what i did: > f = open("test.dat

Re: stripping blanks

2006-05-02 Thread seeker
[EMAIL PROTECTED] wrote: > hi > i have a file test.dat eg > > abcdefgh > ijklmn > <-newline > opqrs > tuvwxyz > <---newline > > I wish to print the contents of the file such that it appears: > abcdefgh > ijklmn > opqrs > tuvwxyz > > here is what i did: > f = open("test.dat

stripping blanks

2006-05-01 Thread micklee74
hi i have a file test.dat eg abcdefgh ijklmn <-newline opqrs tuvwxyz <---newline I wish to print the contents of the file such that it appears: abcdefgh ijklmn opqrs tuvwxyz here is what i did: f = open("test.dat") while 1: line = f.readline().rstrip("\n")