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
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
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
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
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
[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
[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
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")