简体   繁体   English

在python中使用记事(2.7)

[英]Using Memoize in python (2.7)

I do not want to extract files on the disk but keep the final .txt in memory and parse the file. 我不想提取磁盘上的文件,而是将最终的.txt保留在内存中并解析该文件。 I can't find anything using Memoize in python 2.7. 我在python 2.7中使用Memoize找不到任何东西。

.zip -> .gz -> .txt(data needs to be parsed) .zip-> .gz-> .txt(数据需要解析)

My second choice it unzip and parse the .txt file data. 我的第二个选择是将其解压缩并解析.txt文件数据。 Any thoughts? 有什么想法吗?

You can unzip the file and write it to an io.BytesIO object, which is essentially an in memory file. 您可以解压缩文件并将其写入io.BytesIO对象,该对象本质上是一个内存文件。

https://docs.python.org/2/library/io.html#buffered-streams https://docs.python.org/2/library/io.html#buffered-streams

You can then use any function that works for a regular file such as read , seek etc. 然后,您可以使用适用于常规文件的任何功能,例如readseek等。

This case you get a virtual file that works for any format. 在这种情况下,您将获得适用于任何格式的虚拟文件。 If you are certain about the txt is the only thing you are going to use. 如果您确定txt是唯一要使用的东西。 io module also provides other pure text streams. io模块还提供其他纯文本流。

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

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