Python 属性错误:';动物';对象没有属性';获取_name';

Python 属性错误:';动物';对象没有属性';获取_name';,python,class,Python,Class,有谁能帮我解决这个错误,我被难住了。我正在尝试创建一个动物类,为每种动物创建一个名称、情绪和动物类型。无论我如何更改animalGenerator.py,我都会遇到此错误谢谢您的帮助 动物皮 import random class Animal: __animal_type = "" __name = "" __mood = "" def __init__(self, animal_type,

有谁能帮我解决这个错误,我被难住了。我正在尝试创建一个动物类,为每种动物创建一个名称、情绪和动物类型。无论我如何更改animalGenerator.py,我都会遇到此错误谢谢您的帮助

动物皮

import random
class Animal:
    __animal_type = ""
    __name = ""
    __mood = ""
    
    def __init__(self, animal_type, name):
        self.__animal_type = animal_type
        self.__name = name

        num = random.randint(1,3)
        if (num == 1):
            self.__mood = "happy"
        elif (num == 2):
            self.__mood = "hungry"
        elif (num == 3):
            self.__mood = "sleepy"

def get_animal_type(self):
    return self.__animal_type

def get_name(self):
    return self.__name

def check_mood(self):
    return self.__mood
animalGenerator.py

import Animal


print('Welcome to the animal generator!')
print('This program creates Animal objects.')

animals = []

while True:
    animal_type = input("What type of animal would you like to create?")
  
    name = input("What is the animal's name?")
  
    new_animal = Animal.Animal(animal_type, name)
    animals.append(new_animal)
  
    again = input("\nWould you like to add more animals (y/n)? ")
    if(again != 'y'):
        break
  
print("\nAnimal List")

for l in animals:
    print(l.get_name(), 'the', l.get_animal_type(), 'is', l.check_mood())

在Animal.py中检查缩进