Python - 使用变量而不是直接文件名
Python - using variable instead of direct file name
from zipfile import ZipFile
# Create a ZipFile Object and load sample.zip in it
with ZipFile('sampleDir.zip', 'r') as zipObj:
# Extract all the contents of zip file in current directory
zipObj.extractall()
我想使用变量而不是 sampleDir.zip
这样当我将上面的代码放在 for 循环中时,每次都会更改文件名。
from zipfile import ZipFile
# Create a ZipFile Object and load sample.zip in it
var = 'sampleDir.zip'
with ZipFile(var, 'r') as zipObj:
# Extract all the contents of zip file in current directory
zipObj.extractall()
from zipfile import ZipFile
# Create a ZipFile Object and load sample.zip in it
with ZipFile('sampleDir.zip', 'r') as zipObj:
# Extract all the contents of zip file in current directory
zipObj.extractall()
我想使用变量而不是 sampleDir.zip 这样当我将上面的代码放在 for 循环中时,每次都会更改文件名。
from zipfile import ZipFile
# Create a ZipFile Object and load sample.zip in it
var = 'sampleDir.zip'
with ZipFile(var, 'r') as zipObj:
# Extract all the contents of zip file in current directory
zipObj.extractall()