0

I'm trying to learn more Python so I decided to do a school project using python (a simple image processing app).

I'm stuck in this part: I'm trying to initialize two parent class but I can't make it to work.

The error I'm getting is:

TypeError: object.__init__() takes exactly one argument (the instance to initialize).

I fixed two problems reading other questions here, but I can't figure this one out. I hope someone can help me to understand what I'm doing wrong.

class MessageSystem:
    def __init__(self, class_name: str):
        self._class_name = class_name

    def print_status(self, msg: str):
        print(f"{self._class_name} :: {msg}")

    def print_error_status(self, err_msg: str):
        print(f"{self._class_name} :: {err_msg}")


class DataTools:
    def __init__(self, img: np.ndarray):
        self.img = img
        self._rgb_layers = [None, None, None]

    @property
    def img(self):
        return self.img

    @img.setter
    def img(self, value):
        self._img = value
        self.__convert_if_needed_img_to_uint8()
        self.__unstack_layers()

    def __convert_if_needed_img_to_uint8(self):
        if self._img.dtype != np.uint8:
            self.img_as_uint8()

    def __unstack_layers(self):
        for index, layer in enumerate(self._rgb_layers):
            self._rgb_layers[index] = self.img[:, :, index]


class Image(DataTools, MessageSystem):
    def __init__(self, img):
        self._original_img = None
        super(DataTools, self).__init__(img)
        super(MessageSystem, self).__init__("Image") # Error is here

    @DataTools.img.setter
    def img(self, value):
        DataTools.img.__set__(self, value)
        self._original_img = self.img.copy()
        print(f"original: {self._original_img.shape}")
        MessageSystem.print_status("Initialized img and layers")

    def save_to_disk(self, save_path: str):
        """Save processed image as np.uint8 to disk"""
        self.__convert_if_needed_img_to_uint8()
        skimage.io.imsave(save_path, self.img)

I omitted the other non relevant members.

Ahmed
  • 796
  • 1
  • 5
  • 16
Alex
  • 17
  • 1
  • This class deisgn won't work in python. See https://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance for the details. – rdas Nov 10 '20 at 09:49
  • Thank you I'll read that link :) – Alex Nov 10 '20 at 21:40

0 Answers0