【发布时间】:2021-01-20 09:22:13
【问题描述】:
我在运行代码时收到此错误:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: error
但我的文件已关闭,您能帮忙吗?
def delete_employee(self, new_employee):
employees_csv_data = self.open_and_read_file(self.list_of_employees)
with open(EMPLOYEES_EDIT_FILE, 'w') as updated_csv:
writer = csv.writer(updated_csv)
if str(new_employee.employee_id) not in str(employees_csv_data.values):
print(EMPLOYEE_DOESNT_EXIST_IN_FILE_MSG)
else:
for row in employees_csv_data.values:
if new_employee.employee_id != str(row[0]):
writer.writerow(row)
os.rename(EMPLOYEES_EDIT_FILE, self.list_of_employees)
os.remove(self.list_of_employees)
【问题讨论】:
标签: python function csv file class