目前通过Python的速成班工作,这个例子是给我找麻烦NameError:名“name”没有定义
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
""" initializing name and cuisine attributes"""
self.restaurant_name = name
self.cuisine_type = c_type
def greeting(self):
"""simulate greetting with restaurant info..."""
print(self.name.title() + " is a " + self.c_type.title()
+ " type of restaurant.")
def open_or_nah(self):
""" wheteher or not the restaurant is open in this case they will be always"""
print(self.name.title() + " is open af")
china_king = Restaurant('china king', 'chinese')
china_king.greeting
china_king.open_or_nah
控制台一直给我
Traceback (most recent call last):
File "python", line 16, in <module>
File "python", line 4, in __init__
NameError: name 'name' is not defined
我搜索错误为什么造成这个原因,但我无法弄清楚。怎么了?
你的参数被称为'restaurant_name' –