python - 'Animal2' object has no attribute '_Animal2__name' -
this question has answer here:
i wrote in python3.6 using pycharm 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 {} , i'm {}".format(self.__name, self.__sex)) dog = animal2("jerry", "boy") dog.tostring() and keep getting 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 {} , i'm {}".format(self.__name, self.__sex)) attributeerror: 'animal2' object has no attribute '_animal2__name' so i'm wondering if using super() method in wrong way?
please check code above , see what's going on...
:(
Comments
Post a Comment