I'm writing a simple script to search a .txt document for a search word. The script so far will: • Prompt for a file name • Prompt for a word to search for
The prompts work, followed by "TypeError: coercing to Unicode: need string or buffer, list found". I've read other posts on this error, but can't identify why this is happening, so I can move on to the steps: • Open the file in Append mode • Append (print) the number of lines the keyword appears on in the file.
Please note: This worked until I added the user prompts.
import sys
import os
f = file(raw_input("Enter filename: "), 'a')
name_file = raw_input("Input search terms, comma separated: ").lower().split(",")
my_file = open(name_file, "a")
#removed {open(name_file}[0] from above line
search = [x.strip(' ') for x in f]
count = {}