当我尝试解压缩文件并删除旧文件时,它说它仍在运行,所以我使用了关闭功能,但它没有关闭它。
这是我的代码:
import zipfile
import os
onlineLatest = "testFile"
myzip = zipfile.ZipFile(f'{onlineLatest}.zip', 'r')
myzip.extractall(f'{onlineLatest}')
myzip.close()
os.remove(f"{onlineLatest}.zip")
我得到这个错误:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'Version 0.1.2.zip'
有人知道怎么修这个东西吗?
只有之前运行过的其他部分,但不要认为这是问题所在:
request = service.files().get_media(fileId=onlineVersionID)
fh = io.FileIO(f'{onlineLatest}.zip', mode='wb')
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print("Download %d%%." % int(status.progress() * 100))
myzip = zipfile.ZipFile(f'{onlineLatest}.zip', 'r')
myzip.extractall(f'{onlineLatest}')
myzip.close()
os.remove(f"{onlineLatest}.zip")