def get_score_in(low, high): ' 返回指定分数区间的名字,按分数从低到高排序 ' try: conn = sqlite3.connect(db_file) cursor = conn.cursor() cursor.execute('select name from user where score >=? and score <=? order by score', (low, high)) values = cursor.fetchall() return list(map(lambda v: v[0], values)) except BaseException as e: print('Conn Error!', e) finally: cursor.close() conn.close()
好像有个小错误,tuple里索引数字应该是1才能引用名字
return list(map(lambda v: v[1], values))
索引没错啊,二楼自己弄错了吧
索引错乱, v[1]才是名字
如果select × 的话,索引是1,如果select name的话,索引是0。
Sign in to make a reply
Nil_大黄