[Tutor] Tutor Digest, Vol 38, Issue 1

Alan Gauld alan.gauld at btinternet.com
Sun Apr 1 17:46:05 CEST 2007


"Jay Mutter III" <jmutter at uakron.edu> 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.endswith('No.\n'):
      line = line.rstrip()
   print line

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list