我是 python 新手,我很难弄清楚如何从其他模块中的类继承。
模块:~/foo.py
import bar
class foo:
def test(self)
print("this is a test")
模块:~/bar.py
class bar(foo):
def __init__(self):
super().test()
一旦导入 bar,我就会收到此错误消息:
NameError: name 'foo' is not defined
最佳答案
If you want to refer to a name in another module then you must import it.
import foo
class bar(foo.foo):
...
关于python 不同模块的类继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717850/