我想将一个zip文件的内容读入内存中,而不是将其提取到光盘中,在存档中找到一个特定的文件,打开文件并从中提取一行。
可以打开并解析StringIO实例吗?有什么建议吗?提前致谢。
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...
我发现了一些类似的帖子,但似乎都没有解决这个问题:将zip文件提取到内存中?
感谢所有为解决方案做出贡献的人。这就是对我有用的东西:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句