Python 继承不作为教程使用。有什么问题?
我在Pycharm学习“遗传”。 我只是跟着教程走。但它不起作用。有什么问题吗Python 继承不作为教程使用。有什么问题?,python,Python,我在Pycharm学习“遗传”。 我只是跟着教程走。但它不起作用。有什么问题吗 ##Chef.py## class Chef: def make_chicken(self): print("The chef makes a chicken") def make_salad(self): print("The chef makes a salad") def make_special_dish(self): print(
##Chef.py##
class Chef:
def make_chicken(self):
print("The chef makes a chicken")
def make_salad(self):
print("The chef makes a salad")
def make_special_dish(self):
print("The chef makes bbq ribs")
##another.py##
from Chef import Chef
class another(Chef):
##app.py##
from another import another
a = another()
a.make_salad()
运行>>>
错误消息:
Traceback (most recent call last):
File "C:/Users/NEWS1/PycharmProjects/exc/app.py", line 1, in <module>
from another import another
File "C:\Users\NEWS1\PycharmProjects\exc\another.py", line 9
^
SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
回溯(最近一次呼叫最后一次):
文件“C:/Users/NEWS1/PycharmProjects/exc/app.py”,第1行,在
从另一个进口
文件“C:\Users\NEWS1\PycharmProjects\exc\other.py”,第9行
^
SyntaxError:分析时出现意外的EOF
进程已完成,退出代码为1
问题是什么…问题在你的“另一个”类中,冒号后面没有任何内容。您可以向类中添加方法,也可以像这样进行“传递”
##another.py##
from Chef import Chef
class another(Chef):
# other content
pass
您启动了一个没有内容的类块,导致语法错误。您至少需要在类的主体中传递
。有什么问题吗。。。。。SyntaxError?