Creating new archives

suggest change

To create new archive open zipfile with write mode.

import zipfile
new_arch=zipfile.ZipFile("filename.zip",mode="w")

To add files to this archive use write() method.

new_arch.write('filename.txt','filename_in_archive.txt') #first parameter is filename and second parameter is filename in archive by default filename will taken if not provided
new_arch.close()

If you want to write string of bytes into the archive you can use writestr() method.

str_bytes="string buffer"
new_arch.writestr('filename_string_in_archive.txt',str_bytes)
new_arch.close()

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents