Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 继承不作为教程使用。有什么问题?_Python - Fatal编程技术网

Python 继承不作为教程使用。有什么问题?

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(

我在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
回溯(最近一次呼叫最后一次):
文件“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?