我已经使用 tempfile.mkstemp()
创建了临时文件,创建后,我在 path
中获得了文件的唯一路径,现在我想删除临时文件。我的代码如下。
我已经访问过这个WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'new.dat' 但没有解决我的问题。
代码
import os
import tempfile
path=tempfile.mkstemp('.png', 'bingo',
'C:\\Users\\MuhammadUsman\\Documents\\PythonScripts\\Project')
os.unlink(path)
错误
PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'C:\\Users\\MuhammadUsman\\Documents\\PythonScripts\\Project\\bingois3q1b3u.png'
最佳答案
试试这个:这对我有用。
import os
import tempfile
fd,path=tempfile.mkstemp('.png', 'bingo', 'C:\\Users\\MuhammadUsman\\Documents\\Python Scripts\\Project')
os.close(fd)
os.unlink(path)
关于python - 临时文件不可删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50519942/