[Python] Type Error in Python Multiple Inheritance

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have written the below code:

    class Data:
    def __init__(self, name, size_mb):
    self.name = name
    self.size_mb = size_mb

    def info(self):
    return f"Dataset: {self.name}\nSize: {self.size_mb} MB"


    class StructuredData(Data):
    def __init__(self, name, size_mb, columns, rows):
    super().__init__(name, size_mb)
    self.columns = columns
    self.rows = rows

    def info(self):
    return Data.info(self) + f"\nColumns: {self.columns}\nRows: {self.rows}"


    class UnstructuredData(Data):
    def __init__(self, name, size_mb, data_type):
    super().__init__(name, size_mb)
    self.data_type = data_type

    def info(self):
    return super().info() + f"\nData Type: {self.data_type}"


    class BigData(StructuredData, UnstructuredData):
    def __init__(self, name, size_mb, columns, rows, data_type, distributed_storage):
    super().__init__(name, size_mb, columns, rows)
    UnstructuredData.__init__(self, name, size_mb, data_type)
    self.distributed_storage = distributed_storage

    def info(self):
    return (
    super().info()
    + f"\nData Type: {self.data_type}"
    + f"\nDistributed Storage: {self.distributed_storge}"
    )


    `

    but this code raises the below error:

    TypeError: UnstructuredData.__init__() missing 1 required positional argument: 'data_type'


    Do you know how I can fix this error?

    Considering that ChatGPT did not provide me with a suitable solution.

    Continue reading...

Compartilhe esta Página