'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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jean-François Fabre |