Instance attribute attribute_name defined outside __init__

后端 未结 6 1042
不知归路
不知归路 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:32

    For each attribute you want to set via function, call the function from the init. For example, the following works for me to set the attribute ascii_txt...

    def __init__(self, raw_file=None, fingerprint=None):
        self.raw_file = raw_file
        self.ascii_txt = self.convert_resume_to_ascii()
    
    def convert_resume_to_ascii(self):
        ret_val = self.raw_file.upper()
        return ret_val
    

提交回复
热议问题