Instance attribute attribute_name defined outside __init__

后端 未结 6 1022
不知归路
不知归路 2020-11-28 04:18

I split up my class constructor by letting it call multiple functions, like this:

class Wizard:
    def __init__(self, argv):
        self.parse_arguments(ar         


        
6条回答
  •  粉色の甜心
    2020-11-28 04:42

    The idea behind this message is for the sake of readability. We expect to find all the attributes an instance may have by reading its __init__ method.

    You may still want to split initialization into other methods though. In such case, you can simply assign attributes to None (with a bit of documentation) in the __init__ then call the sub-initialization methods.

提交回复
热议问题