【问题标题】:Why I get PermissionError if file is closed? (Python)如果文件已关闭,为什么我会收到 PermissionError? (Python)
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2011-11-29
      • 2018-04-15
      相关资源
      最近更新 更多