要将字符串添加到ZipFile,您需要使用writestr方法,并使用StringIO实例的getvalue方法从StringIO传递字符串
例如
archive.writestr("name of file in zip", my_file.getvalue())请注意,您还需要提供字符串名称,以说明其在zip文件中的位置。

要将字符串添加到ZipFile,您需要使用writestr方法,并使用StringIO实例的getvalue方法从StringIO传递字符串
例如
archive.writestr("name of file in zip", my_file.getvalue())请注意,您还需要提供字符串名称,以说明其在zip文件中的位置。