Discuss / Python / Daily work

Daily work

Topic source

无愠无殇

#1 Created at ... [Delete] [Delete and Lock User]

这个conn.commit()的作用可不可以解释下。提交事务? 是用来做什么的?

def get_score_in(low, high):
    ' 返回指定分数区间的名字,按分数从低到高排序 '
    try:
        con = sqlite3.connect(db_file)
        cursor = con.cursor()
        result = list(cursor.execute('select name from USER WHERE score > %s AND score <= %s ORDER BY score' %(low,high)) )
        li = []
    finally:
        cursor.close()
        con.commit()
        con.close()
    for res in result:
        li.append(res[0])
    return li

  • 1

Reply