python 不同模块的类继承

标签 class inheritance python-3.x module

我是 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

最佳答案

关于python 不同模块的类继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717850/

相关文章:

c++ - 如何在它们之间分配和使用 2 个不同类的函数指针?

javascript - 使用伪经典继承设置原型(prototype)属性

python - python 迭代两个数组的快速方法

Python Pandas 按位置和日期/月份的平均值

python - 将列表输入类中无法取出对象

c++ - 在构造函数定义中调用函数后收到 Segmentation Fault 11 错误?

python - 为比标准套牌中更复杂的扑克牌类型制作类(class)的好方法?

c# - 私有(private)静态变量和实例变量是否在 C# 中继承,为什么?

inheritance - C# 命名参数、继承和重载惊喜

python 在 float 中添加零和随机数字