小编Tim*_*zza的帖子

我应该害怕 __init_subclass__ 开始的方式吗?

我在一个项目中使用init_subclass,当我遇到内置方法时,当代码首次在解释器中运行时启动时,我有点犹豫——没有通过包含类或它的子类的实例化直接引用列举。

有人可以告诉我发生了什么,并指出安全使用的任何示例吗?

class Timer():

    def __init__(self):
        pass

    def __init_subclass__(cls):
        print('Runner.', cls)
        print('Timer Dictionary :', Timer.__dict__.keys())
        # print(Timer.__init_subclass__()) # Forbidden fruit...
        pass

class Event(Timer):
    print("I'll take my own bathroom selfies...thanks anyway.")

    def __init__(self):
        print('This is nice, meeting on a real date.')

if __name__ == '__main__': # a good place for a breakpoint
        date = Event()
        date
Run Code Online (Sandbox Code Playgroud)

编辑 - - - - - - - - - - - - - - - - - - - - - - …

python initialization class subclass enumerable

1
推荐指数
1
解决办法
788
查看次数

标签 统计

class ×1

enumerable ×1

initialization ×1

python ×1

subclass ×1