placid wrote: > Saint Malo wrote: >> Andrew Robert wrote: >>> Saint Malo wrote: >>> # Open a file for read >>> file=open(r'test.txt','r') >>> >>> # Read each line in file >>> for line in file >>> >>> #Search each line >>> if "A" in line: >>> >>> print "I found A" >>> >>> file.close() >
Here's a bit nobody has suggested yet: A) use sets of words for easier checking. ... search_words = set(["red", "brown"]) for line in file: words = set(line.split()) if words & search_words: for word in search_words: if word in words: if word == 'red': print 'weasels rip my flesh' else: print word ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list