How would I open a file by asking for user input? After
filename.txt from the user, I get the error code:
TypeError: coercing to Unicode: need string or buffer, file found
which tells me I need to convert the user input to a string, or format it a different way.
What is the correct way of telling Python
selectfile means "open this file"?
selectfile = file(raw_input("Enter Filename: "), 'r') with open(selectfile, 'r') as inF: with open('outputfile.txt', 'w') as f: for index, line in enumerate(inF): if myString in line: print "Search Term Found!" f.write("Line %d has string: %s" % (index, line)) filename = "outputfile.txt" myfile = open(filename) lines = len(myfile.readlines())