What this program is does is search the text and where the word appear it displays the line. However.
I am recieveing a SyntaxError: EOF while scanning triple-quated string literals. When i try to run in on python 2.6.
I dont have a an option of changeing versions. Just need to fix this error.
Any help will the greatly appreciated

# finding a search word in a text file using regex module re

import re

search = 'work'
# also matches 'like!', but not 'likely'
pattern = r"\b%s\b" % search
#print(pattern)  # for testing only --> \blike\b
rc = re.compile(pattern, re.IGNORECASE)

test_text = """\
1.	Principle of Segmentation:
   	a) Divide an object into independent parts
                 - Replace a large truck by a truck and trailer.
                 - Use a work breakdown structure for a large project.
                 - Sequential novel turn into movies
	b) Make an object easy to disassemble.
		 - Bicycle disassembling (saddle, wheels)
		 - Furniture (sofas, table)
		 - Crib
        c) Increase the degree of fragmentation or segmentation.
                 - Replace solid shades with Venetian blinds
                 - Computer covers with holes for ventilation
		 - Multi blade cartridge Razor

4.	Principle of Asymmetry:
        a.	If an object is symmetrical, change its shape to irregular.
                -Asymmetric paddles mix 
                -cake mixer


fname = "SearchFile.txt"
# save the test text  to a file
fout = open(fname, "w")

# read the file back line by line
word_list = []
for line in open(fname):
    match = rc.search(line)
    if match:
        print(match.group(0))  # for test
6 Years
Discussion Span
Last Post by Danielle87

Works here in Python 2.6.6.


                 - Use a work breakdown structure for a large project.

Of course you do not need re if you do not want to, for example for simple searches of given exact word:

# finding a search word 
fname = "SearchFile.txt"
word = 'to'
for line in open(fname):
    if word in (''.join(c for c in word if c.isalpha()) for word in line.lower().split()):
        print line

Edited by pyTony: n/a


I get the same answer in 2.7
However i have been working on android and trying to fix the code so it runs of the mobile phone. But that error keeps hindering me.

What i am trying to do is not open .txt file and read from there. But search from inside the code and give the result.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.