There is a class:
class signal: lst = [] booklist = None data = [[0, 'nickname' , "nickname"], [1, 'name' , "notempty"]] def __init__(self, row, nrow): for key in self.data: if signal.check(row[key[0]], key[2], "Лист: " + self.booklist + " Строка: " + str(nrow)): setattr(self, key[1], row[key[0]])
Class objects I want to store in the list lst. Why create them in this way in the main body of the program:
signal.lst.append(signal(row, rownum))
That somehow it hurts the eye a little. Therefore, when creating an object, I want to save it in lst immediately in the constructor.
I tried to use a decorator
@classmethod def __init__(cls, self, row, nrow): ... cls.lst.append(self)
But in the main body of the program:
signal(row, rownum)
Then the interpreter scolded me like this:
TypeError: __init__() missing 1 required positional argument: 'nrow'
Is there any elegant solution?
signal(row, rownum)
but thesignal(row, nrow)
that was written, then would it alsosignal(row, nrow)
? - LamerXaKer