I have a class which is declared like:
class K1:
S_LENGTH = 1600
SUFFIX = 0x06
def __init__(self,variant):
self.__state_bytes_length = self.S_LENGTH
self.__delimited_suffix = self.SUFFIX
self.R_LENGTH = self.variant
CAP_LENGTH = self.S_LENGTH - self.R_LENGTH
self.H_LENGTH = CAP_LENGTH/2
self.__rate_bytes_length = self.R_LENGTH
self.__hash_bytes_length = self.H_LENGTH
self.__state_in_bytes = bytearray([0 for i in range(self.__state_bytes_length)])
self.__capacity_bytes_length = self.__state_bytes_length - self.__rate_bytes_length
self.__hash_bytes = bytearray()
I want to take an input value (called variant in my code) from the user and then assign that value to R_LENGTH. When I try to declare it in the aforementioned manner, it throws an error:
AttributeError: 'K1' object has no attribute 'variant'
I am unable to figure out why this error occurs.
R_LENGTH = self.variant. Also indentation of those class variables look wrong.R_LENGTH = variant, without theself. You may have a similar issue withself.__SHA3_HASH_LENGTHlater, since that's not a defined attribute either. I'm not sure how to solve that one.tryandexceptblocks you show in your calling code. If you let an exception bubble out uncaught, the interpreter will generally show you a traceback which identifies exactly where the error occurred. That's useful information, don't throw it away unless you have a good reason!CAP_LENGTH = S_LENGTH - R_LENGTHis another syntax error, either useK1.S_LENGTHorself.S_LENGTHas you did earlier. You need to post working code, otherwise you are just wasting our time.