with filename open(" "as filefile write(contentsdef zip_files(self)with zipfile zipfile(self filename' 'as filefor filename in self temp_directory iterdir()file write(str(filename)filename nameshutil rmtree(str(self temp_directory)if __name__ ="__main__"zipreplace(*sys argv[ : ]zip_find_replace(for brevitythe code for zipping and unzipping files is sparsely documented our current focus is on object-oriented designif you are interested in the inner details of the zipfile modulerefer to the documentation in the standard libraryeither online or by typing import zipfile help(zipfileinto your interactive interpreter note that this example only searches the top-level files in zip fileif there are any folders in the unzipped contentthey will not be scannednor will any files inside those folders the last two lines in the example allow us to run the program from the command line by passing the zip filenamesearch stringand replace string as argumentspython zipsearch py hello zip hello hi of coursethis object does not have to be created from the command lineit could be imported from another module (to perform batch zip file processingor accessed as part of gui interface or even higher-level management object that knows where to get zip files (for exampleto retrieve them from an ftp server or back them up to an external diskas programs become more and more complexthe objects being modeled become less and less like physical objects properties are other abstract objects and methods are actions that change the state of those abstract objects but at the heart of every objectno matter how complexis set of concrete properties and well-defined behaviors removing duplicate code often the code in management style classes such as zipreplace is quite generic and can be applied in variety of ways it is possible to use either composition or inheritance to help keep this code in one placethus eliminating duplicate code before we look at any examples of thislet' discuss tiny bit of theory specificallywhy is duplicate code bad thing