[英]How to move a zip file to a new destination and then open it in python 3
如何将一个zip文件移动到一个新的目标,然后在python 3中打开它。我已经制作了以下代码,但它似乎不适用于zip文件。
import os
source = "C:/Users/sa/Desktop/Pic_ - Im.zip"
destination = "C:/Users/sa/Pictures/pic"
os.rename(source, destination)
这会将zip从一个位置移动到另一个位置,然后将其内容提取到您选择的目录(在本例中为other_dir
)
import shutil
import zipfile
from contextlib import closing
def _unzip(archive, destination):
with closing(zipfile.ZipFile(archive, 'r')) as zip_file:
zip_file.extractall(destination)
SOURCE = "C:/Users/sa/Desktop/Pic_ - Im.zip"
DESTINATION = "C:/Users/sa/Pictures/pic"
shutil.move(SOURCE, DESTINATION)
_unzip(DESTINATION, other_dir)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.