比较来自世界各地的卖家的域名和 IT 服务价格

Python: 从不同的模块导入父母和子公司

我在一个文件中有一个父类,另一个文件在另一个子类中,我试图在第三个中使用它们。 类似的东西:

test1.py


class Parent/object/:
def spam/self/:
print "something"


test2.py


class Child/Parent/:
def eggs/self/:
print "something else"


test3.py


from test1 import *
from test2 import *
test = Child//


跑步 test3.py 给我以下内容:


File "[path]\test2.py", line 1, in <module>
class Child/Parent/:
NameError: name 'Parent' is not defined


我是否需要在同一个地方保留我的父母和子公司?
</module>
已邀请:

董宝中

赞同来自:

您还需要导入模型。
Parent


test2.py



from test1 import Parent

class Child/Parent/:
def eggs/self/:
print "something else"

要回复问题请先登录注册