Notes

Text processing using file operations and lists

Unfortunately, today's Panopto recording got corrupted (I'm sorry). I will remake it if I get the time in the near future.

Today's lecture was changed to give the class more practice using file operations and lists. Specifically, we looked at how we could count the number of times a specific word occurs in a document as well as report back the line numbers that the word appears inside. We walked through writing a function called findWord() that took in a word to find and a file to search. We also used the Python Help Reference in class as we wrote our code to remind ourselves about file operations, string methods, and lists. The sample code below will lead well into tomorrow's lab 11, where you will be working through some text files to count the number of unique words.


Sample Code

Once you load findWord.py into IDLE and press F5 to load the function into memory, type this at the shell to run it:

	findWord("the","preamble.txt")
	

Make sure findWord.py and the preamble.txt file are in the same location (e.g. both on the Desktop).