lass Recipe: def __init__(self): self.set_default_Recipe() return def set_default_Recipe(self): self.recipes = {"cheese omelet":{"eggs":2,"milk":1,"cheese":1}, "mushroom omelet":{"eggs":2,"milk":1,"cheese":1,"mushroom":1}, "onion omelet":{"eggs":2,"milk":1,"cheese":1,"onion":1}} return self.recipes def get(self,name): try: recipe = self.recipe[name] return recipe except KeyError : return False
如下运行:
a = Recipe >>> a.get("banana")
然后报错:
Traceback (most recent call last): File "<pyshell#16>", line 1, in <module> a.get("banana") TypeError: get() missing 1 required positional argument: 'name'
self 应该是实例,前面的a 不就是吗,又为什么说我还缺一个参数呢
求教!
相关分类