0

I'm a rookie at SQLite stuff, and a relative noob in Python. I'm collecting process instrument data for a demonstration application. I've written this code:

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'

The DAQ_Util module is a collection of routines for grabbing process data from instruments. ss2000serialRead is from DAQ_Util and brings in a list of data strings from such an instrument. Some data is reproduced below. All I'm trying to do is write this data to an sqlite table using a list comprehension. It's not working, and I don't know how to interpret the error msg, though I think folks who know more about Python then me may spot the error immediately, or so I hope... :o) A dump of the screen output follows:

$ 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 
$

Can someone please point out the error? Thanks!

Thanks Ignacio, here's corrected code:

# 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)

==== Red

2
  • That's not how LCs... or lists... or Python works. Commented Aug 5, 2012 at 23:14
  • What is instReading? You're iterating over it, but you're also calling it as a function. Is that a typo? Commented Aug 5, 2012 at 23:14

1 Answer 1

3

instReading is already a sequence.

....execute(..., instReading)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ignacio, I just tried that myself, and sure enough.... I think I was thinking too much.... Gotta be careful or I'll hurt myself! :o)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.