I wrote something in python3.6 using Pycharm as follows:
class Animal1:
def __init__(self, name):
self.__name = name
cat = Animal1("Tom")
class Animal2(Animal1):
def __init__(self, name, sex):
self.__sex = sex
super(Animal2, self).__init__(name)
def toString(self):
print("My name is {} and I'm {}".format(self.__name, self.__sex))
dog = Animal2("Jerry", "boy")
dog.toString()
And I just keep getting this weird warning:
Traceback (most recent call last):
File "C:/Users/ZeiYeung/Desktop/my1thpy/main.py", line 30, in <module>
dog.toString()
File "C:/Users/ZeiYeung/Desktop/my1thpy/main.py", line 25, in toString
print("My name is {} and I'm {}".format(self.__name, self.__sex))
AttributeError: 'Animal2' object has no attribute '_Animal2__name'
So I'm wondering if I was using the super() method in a wrong way?
Please check the code above and see what's going on...
:(