将zip解压缩到内存中,解析内容

编程入门 行业动态 更新时间:2024-10-19 23:25:16
本文介绍了将zip解压缩到内存中,解析内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将zip文件的内容读取到内存中,而不是将其提取到光盘中,在存档中找到特定文件,打开文件并从中提取一行.

I want to read the contents of a zip file into memory rather than extracting them to disc, find a particular file in the archive, open the file and extract a line from it.

可以打开并解析StringIO实例吗?有什么建议吗?预先感谢.

Can a StringIO instance be opened and parsed? Suggestions? Thanks in advance.

zfile = ZipFile('name.zip', 'r') for name in zfile.namelist(): if fnmatch.fnmatch(name, '*_readme.xml'): name = StringIO.StringIO() print name # prints StringIO instances open(name, 'r') # IO Error: No such file or directory...

我发现了一些类似的帖子,但似乎都没有解决这个问题:提取zipfile记忆?

I found a few similar posts, but none that seem to address this issue: Extracting a zipfile to memory?

推荐答案

感谢所有提供解决方案的人.这就是对我有用的东西:

Thank you to everyone that contributed solutions. This is what ended up working for me:

zfile = ZipFile('name.zip', 'r') for name in zfile.namelist(): if fnmatch.fnmatch(name, '*_readme.xml'): zopen = zfile.open(name) for line in zopen: if re.match('(.*)<foo>(.*)</foo>(.*)', line): print line

更多推荐

将zip解压缩到内存中,解析内容

本文发布于:2023-11-05 08:07:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解压缩   内存   内容   zip

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!