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
-cement
-truck
-blender
-cake mixer
"""
fname = "SearchFile.txt"
# save the test text to a file
fout = open(fname, "w")
fout.write(test_text)
fout.close()
# 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
print(line)