我目前正在 python 中使用 extratall 函数来解压缩,解压后它还会创建一个文件夹,例如: myfile.zip -> myfile/myfile.zip ,我如何摆脱 myfile flder 并将其解压缩到当前文件夹没有文件夹,可以吗?
最佳答案
我使用标准模块zipfile
。有一个方法 extract
提供了我认为你想要的东西。此方法具有可选参数path
,用于将内容提取到当前工作目录或给定路径
import os, zipfile
os.chdir('path/of/my.zip')
with zipfile.ZipFile('my.zip') as Z :
for elem in Z.namelist() :
Z.extract(elem, 'path/where/extract/to')
如果省略“path/where/extract/to”,ZIP 文件中的文件将被提取到 ZIP 文件的目录中。
关于python - 解压zip文件,不带文件夹python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46954626/