Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
817 B

  1. from zipprocessor import ZipProcessorInh
  2. import sys
  3. import os
  4. class ZipReplace(ZipProcessorInh):
  5. def __init__(self, filename, search_string, replace_string):
  6. super().__init__(filename)
  7. self.search_string = search_string
  8. self.replace_string = replace_string
  9. def process_files(self):
  10. """perform a search and replace on all files in the temporary directory"""
  11. for filename in os.listdir(self.temp_directory):
  12. with open(self._full_filename(filename)) as file:
  13. contents = file.read()
  14. contents = contents.replace(self.search_string, self.replace_string)
  15. with open(self._full_filename(filename), "w") as file:
  16. file.write(contents)
  17. if __name__ == "__main__":
  18. ZipReplace(*sys.argv[1:4]).process_zip()