【问题标题】:Python/SQlite3 'str' object is not callablePython/SQlite3 'str' 对象不可调用
【发布时间】:2015-06-07 11:28:11
【问题描述】:

所以我想用日期和一些二进制数据做一个数据库。我想做的是每 5 分钟,把我的传感器的数据,并把它放在一个有准确时间的数据库中。

这是我的脚本

import serial  # import the serial library
from time import sleep  # import the sleep command from the time library
import sqlite3
import datetime


ser = serial.Serial("/dev/tty.usbserial-A400DUTI", 4800)  # load into a variable 'ser' the information about the usb you are listening. /dev/tty.usbserial.... is the port after plugging in the hygrometer
conn=sqlite3.connect('porjectait.db') #connection with the data base
databa=conn.cursor()
databa.execute('''CREATE TABLE porjectait (date string, temphydro bin)''')
test_file=open("temphydro",'w+b')# creation and/or writing in my binary file

while 1 :
    i = 0
    date=(datetime.datetime.now()) #My way to get the date

    while i < 300 : #300 because it will take at least 2 round of datum

        test_file.write(ser.read(size=1)) #write into my bynary file

        i=i+1

    databa.execute("INSERT INTO porjectait VALUES"('date','test_file')) #insert the datum in my database
    conn.commit()
    sleep(300) #wait 5 minutes

我的第一个问题,但我找到了解决它的方法,我得到了一个:

databa.execute('''CREATE TABLE stock(日期字符串,temphydro bin)''') sqlite3.OperationalError: 表股票已经存在

为了避免这种情况,我只是在 SQL 的创建行前面放了一个#。但我想找到一种方法来检查数据库是否存在,如果不存在则创建它,否则只有更多数据。

然后我的第二个主要问题是当我执行我的脚本时:

databa.execute("插入股票值"('date','test_file')) TypeError: 'str' 对象不可调用

这里是,如果您需要我的二元文件中的内容:

@
I01010100B00725030178
V0109EB01
I02020100B00725030148
V0215FBD9
I035300B5
V030225B8
I04550065
V040294AE
$
@
I01010100B00725030178
V0109EB01
I02020100B00725030148
V02160264
I035300B5
V03022704
I04550065
V040295F0
$
@

谢谢!好久不见

【问题讨论】:

    标签: python datetime sqlite typeerror callable


    【解决方案1】:

    您的 INSERT 字符串错误。结束双引号应放在末尾,例如“INSERT INTO stock VALUES('date','test_file')”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 2019-07-10
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2012-06-04
      相关资源
      最近更新 更多