Python 3:文件和数字资产操作/文件/压缩
外观
from shutil import make_archive
def main():
directory_to_save: str = 'C:\\Data_dir'
output_to: str = 'C:\\Archived.zip'
archive_location: str = make_archive(
output_to,
'zip',
directory_to_save
)
if __name__ == '__main__':
main()
from zipfile import ZipFile
def main():
with ZipFile('test.zip', 'w') as object:
object.write('D:\\main.py', 'main.py')
if __name__ == '__main__':
main()