首页 > 解决方案 > 将@staticmethod 包装器用于魔术方法?

问题描述

在我的一个子类中,我想用以下方法覆盖父类__iter__

def __iter__(self):
    yield from ()

但是,因为我没有引用selfin __iter__,所以写成 pythonic / 可以接受:

@staticmethod
def __iter__():
    yield from ()

标签: pythonpython-3.xclassinheritance

解决方案


推荐阅读