我该如何在Python中压缩文件并指定压缩级别?
目前我有以下代码,但我遇到了错误:
Zip("log4j.dl-service.log.2013-05-03-22",9)
AttributeError: 'str' object has no attribute 'ZipFile'
代码:
import zipfile
import fileinput
def Zip(file,level):
"""
This function uses the zip library native to python to compress files with
Usage: Zip(file,level)
"""
if file and level:
try:
zipfile = file+'.zip'
output = zipfile.ZipFile(zipfile, 'wb')
for line in fileinput.input(file):
output.write(line)
output.close()
if os.path.exists(zipfile):
return zipfile
else:
logMe('critical',"zip failed in Zip()")
return False
except Exception,e:
logMe('critical',e)
ZipFile
的属性,但为什么要让我们猜测呢? - abarnert