我是SQLite的新手,也是Python的相对菜鸟。我正在收集演示应用程序的过程仪表数据。我写了这段代码:
from DAQ_Util import *
from sqlite3 import *
print 'Setting up memory-resident SQL database...'
BenchDB = connect(':memory:')
DBTableSetup = BenchDB.cursor()
DBTableSetup.execute("create table ss2000 (timestamp, var1, var2, var3, var4, var5, var6, var7, var8, var9)")
DBTableSetup.close()
# Access data from SS2000 TDL Sensor
instReading = ss2000serialRead('192.168.1.121', 4001, 57)
print instReading
SS2000TabPopulate = BenchDB.cursor()
SS2000TabPopulate.execute("insert into ss2000 values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[instReading(i) for i in instReading])
print '...Done'
DAQ_Util模块是一组用于从仪器中获取过程数据的例程。 ss2000serialRead
来自DAQ_Util,并从此类工具中引入数据字符串列表。下面复制了一些数据。我要做的就是使用列表推导将此数据写入sqlite
表。它不起作用,我不知道如何解释错误消息,虽然我认为那些了解Python的人然后我可能会立即发现错误,或者我希望......:o)屏幕输出的转储如下:
$ python SQLite-test.py
Setting up memory-resident SQL database...
Try connecting to serial server...
['2012-08-05 16:52:49.548095', '20.0000', '0.0000', '13.5', '76.60', '8190', '1640', '240', '-13', '79.40']
Traceback (most recent call last):
File "SQLite-test.py", line 17, in <module>
[instReading(i) for i in instReading])
TypeError: 'list' object is not callable
$
有人可以指出错误吗? 谢谢!
感谢Ignacio,这是更正后的代码:
# Access data from SS2000 TDL Sensor
instReading = ss2000serialRead('192.168.1.121', 4001, 57)
print instReading
SS2000TabPopulate = BenchDB.cursor()
SS2000TabPopulate.execute("insert into ss2000 values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
instReading)
==== 红色
答案 0 :(得分:3)
instReading
已经一个序列。
....execute(..., instReading)