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
[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:
[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:
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
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
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,