![](/img/trans.png)
[英]Given a list and a bitmask, how do I return the values at the indices that are True?
[英]How do I use list indices to return columns of data instead of rows?
我有一個充滿數據的表,我試圖將它的第 0 列放入 Treeview。 這是我正在使用的代碼
# Query the database
c.execute("SELECT * FROM addresses")
records = c.fetchall()
result_list = [records[0] for record in records]
# Add Data
my_tree.insert(parent='', index='end', iid='PLACEHOLDER', text="", values=(result_list, 1, 2, 3, 1000))
當我這樣做時,它會返回我的整個第 0 行數據,而不是我的第 0 列。
它應該是result_list = [record[0] for record in records]
代替。
最好只在 SQL 語句中使用 SELECT 所需的列,以減少 memory 的使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.