NameError: name 'MysubClass' is not defined
class Displayer:def display(self,message):
print(message)
class loggermixin:
def log(self,message,filename="logfile.txt"):
f.write(message)
def display(self,message):
super().divplay(message)
self.log(message)
class Mysubclass(loggermixin,Displayer):
def log(self,message):
super().log(message,filename="subclasslog.txt")
subclass=MysubClass()
subclass.display("this is a test.")
定义了MysubClass但是显示没有定义,请求大佬帮助 本帖最后由 isdkz 于 2023-2-1 21:43 编辑
class Displayer:
def display(self,message):
print(message)
class loggermixin:
def log(self,message,filename="logfile.txt"):
with open(filename, 'w') as f: # 打开文件
f.write(message)
def display(self,message): #这个缩进不对
super().display(message) #display 打错了
self.log(message)
class Mysubclass(loggermixin,Displayer):
def log(self,message):
super().log(message,filename="subclasslog.txt")
subclass=Mysubclass() # Mysubclass 的 c 是小写
subclass.display("this is a test.") 大小写
Mysubclass 和 MysubClass 不一样 统一一下
页:
[1]