[英]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. 它将字符串作为参数,实际上是要添加到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: 是的,如果你想在你的zip文件中转储一个缓冲区,你可以使用writestr
这样就可以避免创建一个临时文件:
z.writestr(filename,my_buffer)
my_buffer
maybe a str
(string) or bytes
my_buffer
可能是str
(字符串)或bytes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.