Re: [Tutor] print out lines that start with a word

2005-02-09 Thread Alan Gauld
> I'm trying to get only the lines that start with > "This" for a text file. > > Here's what I wrote: > > >>> import re > >>> f = open('c:/lines.txt').readlines() > >>> for line in f: > match = re.search('^This',f) > if line == match: > print match try if line.startwith('This'): its easi

Re: [Tutor] print out lines that start with a word

2005-02-08 Thread Liam Clarke
H Ron, >>> import re >>> f = open('c:/lines.txt').readlines() >>> for line in f: match = re.search('^This',f) if line == match: print match Hi Ron, Welcome to the wonderful world of Python. from re.search.__doc__ ; "Scan through string looking for a match to the

[Tutor] print out lines that start with a word

2005-02-08 Thread Ron Nixon
Can anyone tell me what I've done wrong in this script. I'm trying to get only the lines that start with "This" for a text file. Here's what I wrote: >>> import re >>> f = open('c:/lines.txt').readlines() >>> for line in f: match = re.search('^This',f) if line == match: