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.

24 lines
826 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 temporrary
  11. directory'''
  12. for filename in os.listdir(self.temp_directory):
  13. with open(self._full_filename(filename)) as file:
  14. contents = file.read()
  15. contents = contents.replace(self.search_string, self.replace_string)
  16. with open(self._full_filename(filename), "w") as file:
  17. file.write(contents)
  18. if __name__ == "__main__":
  19. ZipReplace(*sys.argv[1:4]).process_zip()