【发布时间】:2022-06-10 18:11:28
【问题描述】:
```
def run_loop(self):
while True:
event, values = self.read()
if event == None:
break
if event == "_EDIT_":
info = {}
info['first_name'] = values['_FIRST_NAME_'] if len(values['_FIRST_NAME_'].strip()) > 0 else None
info['last_name'] = values['_LAST_NAME_'] if len(values['_LAST_NAME_'].strip()) > 0 else None
info['born'] = values['_BORN_'] if len(values['_BORN_'].strip()) > 0 else None
info['moto'] = values['_MOTO_'] if len(values['_MOTO_'].strip()) > 0 else None
if len(values['_PHOTO_']) != 0:
with open(values['_PHOTO_'], 'rb') as f:
info['photo'] = f.read()
elif self.has_photo == False:
info['photo'] = None
else:
current_employee = employee.WorkerManager.current_employee()
info['photo'] = current_employee.photo
info['employee_id'] = employee.WorkerManager.current_id()
self.close()
```
类员工:
def __init__(self, **employee_info):
self.employee_id = employee_info['employee_id']
self.first_name = employee_info['first_name']
self.last_name = employee_info['last_name']
self.born = employee_info['born']
self.moto = employee_info['moto']
self.photo = employee_info['photo']
self.company_position = employee_info['company_position']
def __str__(self) -> str:
worker_info = []
if self.first_name is not None:
worker_info.append(self.first_name)
if self.last_name is not None:
worker_info.append(self.last_name)
return " ".join(worker_info)
错误名称: self.first_name = employee_info['first_name'] KeyError:'first_name'
多次检查mysql,正确的名称仍然显示错误 谢谢 在 前进
【问题讨论】:
-
也许还没有“编辑”事件?
标签: python