Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
z = zipfile.ZipFile("zipfile.zip", "w") z.write(filename)
它将字符串作为参数,该参数实际上是要添加到 zip 的文件的路径。但我想添加动态生成的文件。
是的,如果您有一个要转储到 zip 文件中的缓冲区,则可以使用writestr它来避免创建临时文件:
writestr
z.writestr(filename,my_buffer)
my_buffer也许是一个str(字符串)或bytes
my_buffer
str
bytes