python - 另一个进程错误使用的文件:Python
问题描述
我试图在一些源文件的帮助下更改目标文件的内容。工作完成后,我确保我已经关闭了代码中的所有文件(当然,我确保它也没有在任何编辑器中打开。)
def write_to_file(self, _source_path, _destination_path):
f_source = open(_source_path, 'r')
f_destination = open(_destination_path, 'r')
f_temp = open(self.temp_path, 'w+')
while source_line or destination_line:...
f_temp.close()
f_destination.close()
f_source.close()
shutil.move(self.temp_path, _destination_path)
return
我收到以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/rohit.tayal/PycharmProjects/AutoNVMerge/MainActivity.py", line 151, in <module>
script.write_to_file(source_path, destination_path)
File "C:/Users/rohit.tayal/PycharmProjects/AutoNVMerge/MainActivity.py", line 62, in write_to_file
shutil.move(self.temp_path, _destination_path)
File "C:\Anaconda\envs\AutoNVMerge\lib\shutil.py", line 581, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\auto_nv_merge.xml'
C:\auto_nv_merge.xml是我的临时文件。
解决方案
工作时
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\auto_nv_merge.xml'
您有 2 个选择,成为英雄并尝试追捕将文件作为人质的进程,或者只是restart
您的计算机。
我通常选择后者,restart
推荐阅读
- javascript - 按钮提醒
- node.js - 如何通过 IntelliJ 运行/调试配置运行 wdio?
- tableau-api - Tableau 在一个工作表中更改 Dimension 的颜色,但在另一个工作表中不更改
- paypal - 被错误地重定向到旧的 PayPal UI
- ruby - Ruby 中的返回整数如何触发“.call”方法?
- angularjs - 如何解析作为路由Angular 1中查询参数的编码url?
- java - 我如何用 JAVA 传递这个 JSON
- python - 如何使用python复制数据以及csv文件中的标题
- javascript - pdfjs移动查看器居中捏缩放
- c# - 从字符串/Json url 获取数据