Discuss / Python / 拼sql语句,整理返回结果的格式。。。

拼sql语句,整理返回结果的格式。。。

Topic source
def get_score_in(low, high):
    #' 返回指定分数区间的名字,按分数从低到高排序 '
    try:
        conn = sqlite3.connect(db_file)
        cursor = conn.cursor()
        cursor.execute('select name from user where score between ? and ? order by score',(low,high))
        values=cursor.fetchall()
    finally:
        cursor.close()
        conn.commit()
        conn.close()
    l=[]
    for data in values:
        l.append(data[0])
    return l

  • 1

Reply