class Restuarant:
def __init__(self,restuarant_name,cuisine_type):
self.name=restuarant_name
self.type = cuisine_type
def describe_restuarant(self):
print(f"{self.name}")
def open_restuarant(self):
print(f"{self.type}")
print("\nRestuarant is opening")
class IcecreamStands:
def __init__(self,flavor='Pepper'):
self.flavor=flavor
def Flavor_describe(self):
print(f"{self.flavor} is my favorite taste")
class IcecreamStand(Restuarant):
def __init__(self,restuarant_name,cuisine_type):
super().__init__(restuarant_name,cuisine_type)
self.flavor=IcecreamStands()
flavor=IcecreamStand("1","2")
flavor.IcecreamStands.Flavor_describe()
报错内容是:Traceback (most recent call last):
File "C:\Users\acer\PycharmProjects\pythonProject\main.py", line 20, in
flavor.IcecreamStands.Flavor_describe()
AttributeError: 'IcecreamStand' object has no attribute 'IcecreamStands'
提示已经说了:AttributeError: 'IcecreamStand'对象没有属性'IcecreamStand'
最后一行修改为flavor.flavor.Flavor_describe()
你在class IcecreamStand的初始化函数定义的是self.flavor,没有IcecreamStands