def pickle_dump(data, filename):
"""Serialize data to file using gzip compression."""
if filename.endswith('.pkz'):
with gzip.open(filename, 'wb') as f:
pickle.dump(data, f, protocol=2) # Try to support python 2.
elif filename.endswith('.jz'):
with gzip.open(filename, 'wt') as f:
f.write(json_dumps(data))
else:
raise ValueError(
'Cannot determine format: {}'.format(os.path.basename(filename)))
评论列表
文章目录