为什么我得到PermissionError如果文件被关闭?(Python)



我得到这个错误,当我运行我的代码:

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)

看起来其他应用程序正在访问该文件。请尝试删除并重新创建,或者重新启动系统。

最新更新