class ClientInfo:
def __init__(
self,
last_name: str = None,
first_name: str = None,
middle_name: str = None,
gender: int = None,
birth_date: OffsetDateTime = None,
**kwargs):
print(kwargs)
self.last_name = kwargs['lastName'] if kwargs else last_name
self.first_name = kwargs['firstName'] if kwargs else first_name
self.middle_name = kwargs['middleName'] if kwargs else middle_name
self.gender = kwargs['gender'] if kwargs else gender
self.birth_date = kwargs['birthDate'] if kwargs else birth_date
print(ClientInfo(**{'gender': '0', 'lastName': 'L', 'middleName': 'M', 'firstName': 'F',
'birthDate': OffsetDateTime('YYYY-MM-DD')
}).last_name)
При попытке запуска файла получаю ошику
Traceback (most recent call last):
{'lastName': 'L, 'middleName': 'M', 'firstName': 'МF, 'birthDate': <app.time.OffsetDateTime object at 0x7fbe9a712e80>}
File "/home/cgrass/PycharmProjects/hivetaxi/app/reg.py", line 30, in <module>
'birthDate': OffsetDateTime('YYYY-MM-DD')
File "/home/cgrass/PycharmProjects/hivetaxi/app/reg.py", line 25, in __init__
self.gender = kwargs['gender'] if kwargs else gender
KeyError: 'gender'
Process finished with exit code 1