Search code examples
pythonpython-3.xsqlitetkintertreeview

How do I use list indices to return columns of data instead of rows?


I have a table full of data and I'm trying to get the 0th column of it into a Treeview. This is the code I'm using

# 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))

When I do this it returns my entire 0th row of data, instead of my 0th column.


Solution

  • It should be result_list = [record[0] for record in records] instead.

    Also better just SELECT the required column in the SQL statement to reduce memory usage.