我在寻找元组/ csv文件/ sqlite的DB记录/ numpy.darray,缓冲可能就像Linux命令“更多”。

过程记录巨大的缓冲代码

在请求从处理巨大数据记录来到(亿行也许),该记录可能看起来像这样:

0.12313 0.231312 0.23123 0.152432
0.22569 0.311312 0.54549 0.224654
0.33326 0.654685 0.67968 0.168749
...
0.42315 0.574575 0.68646 0.689596

我想在numpy.darray处理它们。例如,发现特殊的数据处理它,并将其存回,或处理2周的cols。不过它太大了那么如果numpy的读取文件直接它会给我一个内存错误。

然后,我认为像MEM高速缓存页或Linux的“更多文件”命令可以保存时的处理。

的存储器的适配器

由于这些原始数据可以呈现为不同的格式 - CSV / sqlite_db / HDF5 / XML。我想这个适配器更加规范化,那么,使用“[]”作为“行”可能是一个比较常见的方式,因为我觉得每个记录可以表示为[]。

所以,我想这样可以看起来适配器:

fd = "a opend big file" # or a tuple of objects, whatever, it is an iterable object can access all the raw rows 

page = pager(fd)

page.page_buffer_size = 100    # buffer 100 line or 100 object in tuple

page.seek_to(0)        # move to start
page.seek_to(120)      # move to line #120
page.seek_to(-10)      # seek back to #120

page.next_page()        
page.prev_page()

page1 = page.copy()

page.remove(0)

page.sync()

有人可以展示我一些提示,以防止推倒重来?

顺便提及,ATpy, http://atpy.sourceforge.net/ 是一个模块可以同步在不同的格式的原始数据源的numpy.array,然而,它也读出的所有数据中-A-进入存储器。

而pytable是不适合我,到目前为止,因为SQL不被它并支持HDF5文件可能不一样流行的SQLite数据库(原谅我,如果这是错误的)。

   My plan is write this tools in this way:
    1. helper.py        <-- define all the house-keeping works for different file format
                            |- load_file()
                            |- seek_backword()       
                            |- seek_forward()
                            | ...
    2. adapter.py       <-- define all the interface and import the helper to interact 
                            with raw data and get a way to interact with numpy.darray in somehow.
                            |- load()
                            |- seek_to()
                            |- next_page()
                            |- prev_page()
                            |- sync()
                            |- self.page_buffer_size
                            |- self.abs_index_in_raw_for_this_page = []
                            |- self.index_for_this_page = []
                            |- self.buffered_rows = []

谢谢,

RGS,

KC

有帮助吗?

解决方案

Ummmm ....你不是真的在谈论任何超过列表。

fd = open( "some file", "r" )
data =  fd.readlines()

page_size = 100

data[0:0+page_size] # move to start
data[120:120+page_size] # move to line 120
here= 120
data[here-10:here-10+page_size] # move back 10 from here
here -= 10
data[here:here+page_size]
here += page_size
data[here:here+page_size]

我不知道你实际上需要创造任何东西。

其他提示

linecache 模块可能是有益的 - 你可以调用getline(filename, lineno)有效地检索从线给定的文件。

你还是要弄清楚屏幕有多高和宽是。快速googlance表明,大约有14种不同的方式来做到这一点,其中一些可能已经过时。该诅咒模块可能是你最好的选择,我会想,如果你想成为必要能够顺利地向后滚动。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top