我有来自包含仪器读数的 XML 解析器的数据。数据样本复制如下:
cimReading = [['2012-08-15 10:05:13.101485', ['0x46'], ['0x32'], ['1.234'], ['5.678'], ['9.123'],
['4.567'], ['0x98'], ['0x97']],
['2012-08-15 10:05:13.101979', ['0x47'], ['0x33'], ['8.901'], ['2.345'], ['6.789'],
['0.123'], ['0x96'], ['0x95']]]
我正在尝试遍历列表项并将它们放在一个表中,cim76_dmt
该表以前在 Python 中用sqlite3
. 这是我用来尝试执行此操作的代码:
for devList in cimReading:
print devList
cim76TabPopulate.execute('INSERT INTO cim76_dmt VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
devList)
BenchDB.commit()
cim76TabPopulate.close()
这是我在执行时收到的错误消息:
['2012-08-15 10:40:21.110140', ['0x46'], ['0x32'], ['1.234'], ['5.678'], ['9.123'], ['4.567'], ['0x98'], ['0x97']]
EXCEPTION...
(<class 'sqlite3.InterfaceError'>, InterfaceError('Error binding parameter 1 - probably unsupported type.',), <traceback object at 0x1007a7518>)
所以,我在将列表项映射到 SQL 表字段时遇到问题。我认为应该有一种方法可以做到这一点,但另一种可能性可能是调整 XML 解析,以便为每条记录生成一个包含多个字符串的单个列表。我欢迎对此提出任何建议或意见。
提前致谢!