my code;
items_orderedSQL = cursor.fetchall()
print(f"\n{cust_name} ordered;\n{items_orderedSQL}")
I want to print a table, but its outputting this;
[('Bauble', 4), ('Tinsel', 3), ('Tree', 7)]
However I don' t want the extra characters, I want it to be user friendly but I am not sure how to going around this. Preferably I'd like it to output;
Bauble - 4
Tinsel - 3
Tree - 7
or something similar. Thank you. (sqlite3)
CodePudding user response:
How about this:
items_orderedSQL = [('Bauble', 4), ('Tinsel', 3), ('Tree', 7)]
for item in items_orderedSQL:
print(f"{item[0]} - {item[1]}")
items_orderedSQL
is a list of tuples. The for
loop walks through the list, and each of the two items in the tuple is accessed by index.