import zipfile
import os,shutil
src_dir = os.path.expanduser("xxxx/.klang")
targetname = 'stockdata.zip'
print("正在压缩文件")
z = zipfile.ZipFile(targetname, 'w', zipfile.ZIP_DEFLATED) # 参数一:文件夹名
for dirpath, dirnames, filenames in os.walk(src_dir):
fpath = dirpath.replace(src_dir, '')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
z.write(os.path.join(dirpath, filename), fpath+filename)
print (fpath+filename)
z.close()
shutil.move(targetname,os.path.expanduser("xxx/xxx/public/"+targetname))