Skip to content Skip to sidebar Skip to footer

Importerror: Cannot Import Name Mainclass

society. I'm trying to understand the OOP programming and I'm facing some issues and asking for help. Here the example: I'm trying to create all objects under one class and then I

Solution 1:

I changed your code to this:

baseclass.py

import first
import second

classMainClass:
    def__init__(self):
        self.firstclass = first.FirstClass()
        self.secondclass = second.SecondClass()

first.py

import baseclass

classFirstClass(baseclass.MainClass):def__init__(self):
        baseclass.MainClass.__init__(self)

    defadd_two_number(self):
        return2 + 2

second.py

import baseclassclass SecondClass():
    def__init__(self):
        baseclass.MainClass.__init__(self)

    defminus_number(self):
        return self.firstclass.add_two_number() - 10if __name__ == '__main__':
    print(second.SecondClass().minus_number())

I get no ImportErrors or any errors of any kind. I think your ImportError had something to do with from instead of just import. I hope this helps.

Post a Comment for "Importerror: Cannot Import Name Mainclass"