Re: [Tutor] Tutor Digest, Vol 38, Issue 1

2007-04-01 Thread Alan Gauld
"Jay Mutter III" <[EMAIL PROTECTED]> wrote > inp = open('test.txt','r') > s = inp.readlines() > for line in s: > if line.endswith('No.'): > line = line.rstrip() > print line BTW, You do know that you can shorten that considerably? With: for line in open('test.txt'): if line.

Re: [Tutor] Tutor Digest, Vol 38, Issue 1

2007-04-01 Thread Alan Gauld
"Rikard Bosnjakovic" <[EMAIL PROTECTED]> wrote s1 = "some line\n" s2 = "some line" s1.endswith("line"), s2.endswith("line") > (False, True) > > Just skip the if and simply rstrip the string. Or add \n to the endswith() test string if you really only want to strip the newline in

Re: [Tutor] Tutor Digest, Vol 38, Issue 1

2007-04-01 Thread Rikard Bosnjakovic
On 4/1/07, Jay Mutter III <[EMAIL PROTECTED]> wrote: > For some reason this never works for me; That's because you are ignoring the linefeed character: [...] > if line.endswith('No.'): >>> s1 = "some line\n" >>> s2 = "some line" >>> s1.endswith("line"), s2.endswith("line") (False, True) J

Re: [Tutor] Tutor Digest, Vol 38, Issue 1

2007-04-01 Thread Jay Mutter III
Alan thanks for the response; > Message: 8 > Date: Sun, 1 Apr 2007 08:54:02 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Another parsing question > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; >