Property setter with multiple values

后端 未结 5 1155
星月不相逢
星月不相逢 2020-12-09 11:55

I have a property setter which generates a unique id by taking two strings and hashing it:

@id.setter
def id(self,value1,value2):
    self._id = sha512(value         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 12:14

    The setter can only take one value, so use a tuple: (value1, value2).

    @id.setter
    def id(self,value):          
        self._id = sha512(str(value))
    
    ...
    
    self.id = (value1, value2)
    

    (You didn't post what sha512 is. I'm assuming you are using hashlib.sha512, and sha512 is calling the update method, which requires a string as input.)

提交回复
热议问题