First, your whole_thing variable should be text_file.read() if you want to return all the contents as a string. Or text_file.readlines() if you want to return all the contents as a list of each line. Change this and see if that fixes any problems with your code.
I don't fully understand what you mean by "search results", but I assume you mean the single_line variable if the room number is in that line. If you want to write that line to the "courseinfo.dat" file, the just stick that writing segment inside where you are currently printing the single_line. Like this:
single_line = whole_thing.split('\n')
for single_line in text_file.readlines():
if room_num in single_line:
fileObj = open("courseinfo.dat","w")
fileObj.write(single_line)
fileObj.close() If this isn't what you meant, please rephrase your question clearly and maybe include some sort of example of what "roombookings.txt" contains, etc.
shadwickman
Posting Pro in Training
497 posts since Jul 2007
Reputation Points: 186
Solved Threads: 77