from pathlib import path class zipreplacedef __init__(selffilenamesearch_stringreplace_string)self filename filename self search_string search_string self replace_string replace_string self temp_directory path("unzipped-{}formatfilename)thenwe create an overall "managermethod for each of the three steps this method delegates responsibility to other methods obviouslywe could do all three steps in one methodor indeedin one script without ever creating an object there are several advantages to separating the three stepsreadabilitythe code for each step is in self-contained unit that is easy to read and understand the method names describe what the method doesand less additional documentation is required to understand what is going on extensibilityif subclass wanted to use compressed tar files instead of zip filesit could override the zip and unzip methods without having to duplicate the find_replace method partitioningan external class could create an instance of this class and call the find_replace method directly on some folder without having to zip the content the delegation method is the first in the following codethe rest of the methods are included for completenessdef zip_find_replace(self)self unzip_files(self find_replace(self zip_files(def unzip_files(self)self temp_directory mkdir(with zipfile zipfile(self filenameas zipzip extractall(str(self temp_directory)def find_replace(self)for filename in self temp_directory iterdir()with filename open(as filecontents file read(contents contents replaceself search_stringself replace_string