class di: booklist = "DI" data = {'nickname' : "nickname", 'in' : "in", 'category' : "int", 'log' : "bool", 'name' : 'notempty', 'inversion' : "bool", 'ton' : "s5time", 'tof' : "s5time", 'module' : "notempty", 'cleath' : "notempty", 'device' : "notempty"} def __init__(self, row, nrow): i = 0 for key in data if check(row[i], data[key], "Лист: " + booklist + " Строка: " + str(nrow)): self.[key] = row[i] i = i + 1 

Is there any instruction in Python that would work like self.[key] ?

    1 answer 1

    setattr seems most suitable for such a case. Or you can work directly with __dict__