import zipfile
import os
startdir = './test/neg'
file_news = './test_neg.zip'z = zipfile.ZipFile(file_news, 'w',zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(startdir):
fpath = dirpath.replace(startdir, '')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
z.write(os.path.join(dirpath, filename), fpath + filename)
print( '压缩成功')
z.close()