【发布时间】:2021-03-26 12:02:57
【问题描述】:
所以我收到了这个错误:
self.list_of_employees.write(new_employee_data)
AttributeError: 'str' object has no attribute 'write'
我不明白我的代码有什么问题:
def add_employee(self, new_employee):
new_employee_data = [new_employee.employee_id, new_employee.name, new_employee.phone, new_employee.age]
with open(self.list_of_employees, 'r+') as file1:
existing_lines = csv.reader(file1)
for row in existing_lines:
if new_employee_data in row:
print("Sorry, the employee is already exist.")
return
self.list_of_employees.write(new_employee_data)
如果有任何帮助,我将不胜感激!
【问题讨论】: