stripping blanks

2006-05-02 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) if

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) while 1:

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) while 1:

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

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 you mean,