【发布时间】:2019-06-21 18:03:59
【问题描述】:
我正在尝试从 python 中的 sqlite3 数据库中获取 user_id 并存储在一个数组中。这是我尝试过的:
LIST_ARRAY=[]
def start(bot, update):
value = update.message.from_user.id
print("VALUE first: ", value)
try:
for row in connection.execute("SELECT *from userdetails WHERE user_id=?", (value,)):
print(row)
user_id, full_name, address, phone_number, email = row
data = [user_id]
LIST_ARRAY[0] = data[0]
except:
print(LIST_OF_ADMINS)
它没有得到值,请帮我解决这个问题。
我的数据变量没有被添加到列表数组中
【问题讨论】:
-
也许从查看docs开始
-
首先注意
list和array是不同的。您正在使用数组表示法将数据添加到列表中。使用LIST_ARRAY.append(data[0]) -
“它没有得到值”。那么,它在做什么?如果您的答案不是“它因 IndendationError 而崩溃”,请edit您的帖子,以便缩进与您的实际代码中的内容相匹配。
-
去掉
try/except,然后看看错误是什么。了解如何创建minimal reproducible example。 -
如果一行代码不能产生您试图捕获的异常,它可能不属于
try块。并且except应该总是例外:至少Exception,以避免捕获像SystemExit这样的东西,但越专注越好。
标签: python python-3.x python-2.7 logic