Python中的可编辑数据表显示
我有一个python(2.7)脚本,它通过串行端口以以下形式读取传入数据:Python中的可编辑数据表显示,python,datatable,Python,Datatable,我有一个python(2.7)脚本,它通过串行端口以以下形式读取传入数据: ID: 648 Data: 45 77 33 9C 26 9A 1F 42 ID: 363 Data: 35 74 36 BC 26 9D ... 数据流包含几个不同的ID(大约30个),它们以2-8个数据字节周期性地重复。ID的频率范围为10-120毫秒。一些ID的重复频率比其他ID的要快 无论如何,我有一个基本的python脚本,它将这个流读入2个变量(id和数据): 我想做的是以数据表格式实时显示这些数据,其中
ID: 648 Data: 45 77 33 9C 26 9A 1F 42
ID: 363 Data: 35 74 36 BC 26 9D
...
数据流包含几个不同的ID(大约30个),它们以2-8个数据字节周期性地重复。ID的频率范围为10-120毫秒。一些ID的重复频率比其他ID的要快
无论如何,我有一个基本的python脚本,它将这个流读入2个变量(id和数据):
我想做的是以数据表格式实时显示这些数据,其中新的ID条目被添加到表中,重复的ID条目被更新。这将产生一个表,该表最初会随着ID的发现而增长,然后随着ID数据的更改而更新
我已经看到了一些表模块的示例,它们允许您向表中添加行,但我还需要能够修改现有条目,因为这是最常见的情况
我对python还是相当陌生的,我需要一个没有过多开销的实现来尽可能快地更新数据
有什么想法吗??
提前谢谢 是终端显示的目标
#!/usr/bin/env python
import curses
import time
def updater():
fakedata = [[1, 78], [2, 97], [1, 45], [2, 2], [3, 89]]
codes_to_linenums_dict = {}
last_line = 0
win = curses.initscr()
for code, data in fakedata:
try:
# if we haven't seen this code before, give it the next line
if code not in codes_to_linenums_dict:
codes_to_linenums_dict[code] = last_line
last_line += 1
# use the line we set for this code.
line = codes_to_linenums_dict[code]
win.addstr(line, 0, '{}: {} '.format(code, data))
win.refresh()
# For display only
time.sleep(2)
except KeyboardInterrupt:
# if endwin isn't called the terminal becomes unuseable.
curses.endwin()
raise
curses.endwin()
if __name__ == '__main__':
updater()
~看起来很有前途,但是没有windows版本??
#!/usr/bin/env python
import curses
import time
def updater():
fakedata = [[1, 78], [2, 97], [1, 45], [2, 2], [3, 89]]
codes_to_linenums_dict = {}
last_line = 0
win = curses.initscr()
for code, data in fakedata:
try:
# if we haven't seen this code before, give it the next line
if code not in codes_to_linenums_dict:
codes_to_linenums_dict[code] = last_line
last_line += 1
# use the line we set for this code.
line = codes_to_linenums_dict[code]
win.addstr(line, 0, '{}: {} '.format(code, data))
win.refresh()
# For display only
time.sleep(2)
except KeyboardInterrupt:
# if endwin isn't called the terminal becomes unuseable.
curses.endwin()
raise
curses.endwin()
if __name__ == '__main__':
updater()