相关疑难解决方法(0)

在__init__外定义的实例属性attribute_name

我通过让它调用多个函数来拆分我的类构造函数,如下所示:

class Wizard:
    def __init__(self, argv):
        self.parse_arguments(argv)
        self.wave_wand() # declaration omitted

    def parse_arguments(self, argv):
        if self.has_correct_argument_count(argv):
            self.name = argv[0]
            self.magic_ability = argv[1]
        else:
            raise InvalidArgumentsException() # declaration omitted

# ... irrelevant functions omitted
Run Code Online (Sandbox Code Playgroud)

当我的口译员愉快地运行我的代码时,Pylint抱怨:

Instance attribute attribute_name defined outside __init__

粗略的Google搜索目前毫无结果.保持所有构造函数逻辑__init__似乎没有组织,并且关闭Pylint警告似乎也是黑客攻击.

什么是/ Pythonic解决这个问题的方法?

python constructor pylint

136
推荐指数
2
解决办法
6万
查看次数

标签 统计

constructor ×1

pylint ×1

python ×1