0

我在使数据库与 webiopi 一起工作时遇到了一些问题。我已经导入 sqlite3 并更改文件夹权限,但是当我运行 webiopi 时,什么都没有创建。但是,f.write('This is a test\n')每个过程之后的其他功能正常工作并重复循环。希望你能帮我?

def loop():
    db = sqlite3.connect('schedule.db')
    db.execute('DROP TABLE IF EXISTS schedule')
    db.execute('CREATE TABLE schedule (hour int, minute int, second int, status text)')
    db.execute('INSERT INTO schedule (hour,minute,second,status) VALUES (?,?,?,?)',(sche.get('hour'),sche.get('minute'),sche.get('second'),"yes"))
    db.commit()
    f = open('workfile', 'w')
    f.write('This is a test\n')
    loop1=1
    while ((now.minute >= minute_ON) and (now.minute < minute_OFF) and (loop1<stepping)):
        step()
        loop1=loop1+1

谢谢

4

1 回答 1

0

对于数据库,您可以使用 cursor 和 conn 更好。有关更多信息,请参阅文档

对于文件,close()当您不将其用于写入数据时,您可以使用它。下面的代码可能会有所帮助:

def loop():
    db = sqlite3.connect('schedule.db')
    cur = db.cursor() # create a cursor
    cur.execute('DROP TABLE IF EXISTS schedule')
    cur.execute('CREATE TABLE schedule (hour int, minute int, second int, status text)')
    cur.execute('INSERT INTO schedule (hour,minute,second,status) VALUES (?,?,?,?)',(sche.get('hour'),sche.get('minute'),sche.get('second'),"yes"))
    db.commit()

    cur.close() # close cursor
    db.close() # close connection to sqlite3

    f = open('workfile', 'w')
    f.write('This is a test\n')
    f.close() # close file to write data

    loop1=1
    while ((now.minute >= minute_ON) and (now.minute < minute_OFF) and (loop1<stepping)):
        step()
        loop1=loop1+1
于 2015-01-24T07:53:53.800 回答