简体   繁体   中英

how to add dynamically generated pdf file to zipfile Python?

z = zipfile.ZipFile("zipfile.zip", "w")
z.write(filename)

It takes string as an argument that is actually path of that file to be add to the zip. But I want to add dynamically generated file.

yes, if you have a buffer you want to dump in your zip file, you can use writestr so you avoid creating a temp file:

z.writestr(filename,my_buffer)

my_buffer maybe a str (string) or bytes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM