[Tutor] print out lines that start with a word

Ron Nixon nixonron at yahoo.com
Wed Feb 9 06:36:55 CET 2005

Can anyone tell me what I've done wrong in this

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

here's the error message I got:

Traceback (most recent call last):
  File "<pyshell#34>", line 2, in -toplevel-
    match = re.search('^This',f)
  File "C:\Python24\lib\sre.py", line 134, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or buffer

Thanks in advance

Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 

More information about the Tutor mailing list