首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sql或sqlite的Webiopi (Raspberry pi)

使用sql或sqlite的Webiopi (Raspberry pi)
EN

Stack Overflow用户
提问于 2015-01-24 07:36:48
回答 1查看 707关注 0票数 0

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

代码语言:javascript
复制
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

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-24 07:53:53

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

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

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28123371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档