猿问

求教:python中类的问题!一下代码一直报错

def __init__(self,kind = "cheese"):
        self.set_kind(kind)
        return
def set_kind(self,kind): 
    possible_ingredients = self.__known_kinds(kind)
    if possible_ingredients == False:
        return False
    else:
        self.kind = kind
        self.needed_ingredients = possible_ingredients

以上代码都是Omelet类中的函数

AttributeError: 'Omelet' object has no attribute '_Omelet__known_kinds'如此报错

求助!(鞠躬)

def __known_kinds(self,kind):
            if kind == "cheese":
                return{"eggs":2,"milk":1,"cheese":1}
            elif kind == "mushroom":
                return{"eggs":2,"milk":1,"cheese":1,"mushroom":2}
            elif kind == "onion":
                return{"eggs":2,"milk":1,"cheese":1,"onion":1}
            else:
                return False



22with33
浏览 1354回答 5
5回答

Eric_温水之蛙

代码没有贴全吗? 报错提示缺少known_kind

Eric_温水之蛙

代码没有贴全吗? 报错提示缺少known_kind
随时随地看视频慕课网APP

相关分类

Python
我要回答