this is why programmersespecially python programmers (who tend to value elegant code more than average)follow what is known as the don' repeat yourself (dryprinciple dry code is maintainable code my advice to beginning programmers is to never use the copy and paste feature of their editor to intermediate programmersi suggest they think thrice before they hit ctrl but what should we do instead of code duplicationthe simplest solution is often to move the code into function that accepts parameters to account for whatever parts are different this isn' terribly object-oriented solutionbut it is frequently optimal for exampleif we have two pieces of code that unzip zip file into two different directorieswe can easily write function that accepts parameter for the directory to which it should be unzipped instead this may make the function itself slightly more difficult to readbut good function name and docstring can easily make up for thatand any code that invokes the function will be easier to read that' certainly enough theorythe moral of the story isalways make the effort to refactor your code to be easier to read instead of writing bad code that is only easier to write in practice let' explore two ways we can reuse existing code after writing our code to replace strings in zip file full of text fileswe are later contracted to scale all the images in zip file to looks like we could use very similar paradigm to what we used in zipreplace the first impulse might be to save copy of that file and change the find_replace method to scale_image or something similar butthat' uncool what if someday we want to change the unzip and zip methods to also open tar filesor maybe we want to use guaranteed unique directory name for temporary files in either casewe' have to change it in two different placeswe'll start by demonstrating an inheritance-based solution to this problem first we'll modify our original zipreplace class into superclass for processing generic zip filesimport os import shutil import zipfile from pathlib import path class zipprocessordef __init__(selfzipname)self zipname zipname