This assignment extends a program you wrote for Lab 8, grep. The focus of the assignment is to practice breaking a problem down into smaller pieces. You also will get to practice writing a function and working with files and strings.
Download this zip file. Its contents are explained in the next section.
Note the unusual due date.
Use your solution for grep as a starting point. If your code is incomplete and incorrect, feel free to use my implementation of grep from Session 16 as your starting point.
You will also want to use two modules in your program:
Finds the positions of all occurrences of target in source that occur in the range start ≤ position < end. Returns a string containing zero or more indices, separated by commas.
Returns a collection of the names of all the text files in the current directory.
for filename in get_files(): # suite of statements using filename
You can import these functions into your program by including these lines at the top of the file:
from str_utils import multi_find from homework09 import get_files
The zip file contains grep.py, str_utils.py, and homework09.py, along with several large text files you can use to test your program.
Write a program that
For example, with the files in your test directory:
>>> search for: er >>>
... will produce the following output.dat:
*** File searched = dirda-excerpts.txt *** Total matches = 46 4 Some people will never learn anything, for this reason, 5 because they understand everything too soon. ... 108 Ralph Waldo Emerson, Essays / Journals 109 John Henry Newman, The Idea of a University *** File searched = hamlet.txt *** Total matches = 1970 12 Dramatis Personae 15 Marcellus, Officer. ... 4458 Go, bid the soldiers shoot. 4459 Exeunt marching; after the which a peal of ordnance *** File searched = macbeth.txt *** Total matches = 1124 8 Dramatis Personae 11 MACBETH, Thane of Glamis and Cawdor, a general in the King's army ... 2842 Took off her life; this, and what needful else 2844 We will perform in measure, time, and place. *** File searched = midsummer-nights-dream.txt *** Total matches = 1308 2 A MIDSUMMER NIGHT'S DREAM 8 DRAMATIS PERSONAE ... 2398 Now to scape the serpent's tongue, 2399 We will make amends ere long; *** File searched = test.txt *** Total matches = 10 12 Dramatis Personae 15 Marcellus, Officer. ... 22 Rosencrantz, courtier. 23 Guildenstern, courtier.
Notice that:
Here is some design and programming advice:
Name your program search_files.py.
Run the final version of your program using at least three different search strings with the text files in the zip directory. Make sure you choose strings that demonstrate the features of your program.
Make sure to copy your output.dat file before overwriting it with another run!
If You Don't Get Done. Turn in the latest version of your program that runs. Clearly document in your header block which features are implemented and which features are not implemented.
It is better to turn in incomplete code that works than code that doesn't work.
By the due date and time, submit:
Use the on-line submission system.
Make sure that your program meets the course programming standards.