我正在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("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
是什么问题。...
问题出在您的“另一个”课程中,冒号后面没有任何内容。您可以将方法添加到类中,也可以像这样通过“传递”]
##another.py##
from Chef import Chef
class another(Chef):
# other content
pass