简体   繁体   English

如何将字符串作为文件处理以构造 ZipFile 对象?

[英]How to process a string as a file to contruct a ZipFile object?

I am currently pulling data from a database with blobs.我目前正在从带有 blob 的数据库中提取数据。 I retrieve the blob from the database, but I need to parse the text.我从数据库中检索 blob,但我需要解析文本。 the ZipFile class takes in files not strings, so what would be a good way to solve this? ZipFile 类接受文件而不是字符串,那么解决这个问题的好方法是什么?

import zipfile

data= request.files["file"].read() #this is just binary data
zipfile.ZipFile(data)

use io.BytesIO or io.StringIO使用 io.BytesIO 或 io.StringIO
essentially u just need file-like interface本质上你只需要类似文件的界面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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