Discuss / Python / http code 400是指参数错误,没有填标题的话

http code 400是指参数错误,没有填标题的话

Topic source

林金壕

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-

import os, sqlite3

# 移除已有的文件,以免对测试造成干扰
db_file = os.path.join(os.path.dirname(__file__), 'test.db')
if os.path.isfile(db_file):
    os.remove(db_file)

# 初始数据:
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
cursor.execute('create table user(id varchar(20) primary key, name varchar(20), score int)')
cursor.execute(r"insert into user values ('A-001', 'Adam', 95)")
cursor.execute(r"insert into user values ('A-002', 'Bart', 62)")
cursor.execute(r"insert into user values ('A-003', 'Lisa', 78)")
cursor.close()
conn.commit()
conn.close()

def get_score_in(low, high):
    ' 返回指定分数区间的名字,按分数从低到高排序 '
    with sqlite3.connect(db_file) as conn:
        cursor = conn.cursor()
        cursor.execute('select * from user where score between ? and ? order by score', (low, high))
        value = cursor.fetchall()
        value = list(map(lambda x: x[1], value))
    return value

# 测试:
assert get_score_in(80, 95) == ['Adam'], get_score_in(80, 95)
assert get_score_in(60, 80) == ['Bart', 'Lisa'], get_score_in(60, 80)
assert get_score_in(60, 100) == ['Bart', 'Lisa', 'Adam'], get_score_in(60, 100)

print('Pass')

家乡卢龙

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

value = list(map(lambda x: x[1], value))

是不是应该改成

value = list(map(lambda x: x[0], value))

家乡卢龙

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

哦不对, 应该是1,不用改,SORRY

为啥是1?能帮忙解释一下吗


  • 1

Reply