From 4e387a3dc34b8ddb848a25ae4890b91561fc1e5b Mon Sep 17 00:00:00 2001 From: tmeissner Date: Tue, 7 Oct 2014 22:15:32 +0200 Subject: [PATCH] added new zipscale variant which uses composition instead of inhiterance --- python_3_oop/chapter05/zipscale_comp.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python_3_oop/chapter05/zipscale_comp.py diff --git a/python_3_oop/chapter05/zipscale_comp.py b/python_3_oop/chapter05/zipscale_comp.py new file mode 100644 index 0000000..6b25d9e --- /dev/null +++ b/python_3_oop/chapter05/zipscale_comp.py @@ -0,0 +1,19 @@ +from zipprocessor import ZipProcessorComp +import sys +import os +from pygame import image +from pygame.transform import scale + + +class ZipScale(): + + def process(self, zipprocessor): + """Scale each image in the directory to 640x480""" + for filename in os.listdir(zipprocessor.temp_directory): + im = image.load(zipprocessor._full_filename(filename)) + scaled = scale(im, (640, 480)) + image.save(scaled, zipprocessor._full_filename(filename)) + + +if __name__ == "__main__": + ZipProcessorComp(sys.argv[1], ZipScale()).process_zip()