【发布时间】:2016-11-11 10:07:33
【问题描述】:
我有一个基类 Base,它位于模块 base.py 中。
class Base:
def __init__(self):
print(self.__module__)
此外,模块child.py 中还有一个子类Child。
from test.base import Base
class Child(Base):
pass
if __name__ == '__main__':
c = Child()
我运行python child.py。
我希望声明 print(self.__module__) 打印 child 或 child.py,而不是当前打印的 __main__。
附:无需在子类中重新定义 init 方法
【问题讨论】:
标签: python python-3.x oop