为了账号安全,请及时绑定邮箱和手机立即绑定

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

/ 猿问

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

22with33 2018-08-07 14:18:44
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



查看完整描述

2 回答

?
Eric_温水之蛙

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

查看完整回答
反对 回复 2018-08-07
?
Eric_温水之蛙

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

查看完整回答
反对 回复 2018-08-07

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信