Jul-24-2023, 07:23 PM
(This post was last modified: Jul-24-2023, 07:23 PM by deanhystad.)
I don't understand your posts. Are you making or querying a database? Maybe you should post some more code to provide context.
If you are querying a database, the query returns the columns as part of the description. Using the cars database created by my previous post:
If you are querying a database, the query returns the columns as part of the description. Using the cars database created by my previous post:
import sqlite3 as sql conn = sql.connect("cars.db") cars = conn.cursor().execute("SELECT * FROM makes") columns = [car[0] for car in cars.description] print(columns) print(*list(cars), sep="\n") conn.close
Output:['index', 'make', 'wheels', 'colour']
(0, 'Ford', '4', 'black')
(1, 'Mercedes', '4', 'white')
(2, 'Robin', '3', 'rusty yellow')
If you are creating a database, you should not use individual variables to represent a collection. Your code should not have ford or reliant or audi. You should have a list of cars, or better yet you should read a table of cars from a CSV file or have a GUI that allows entering cars. As far as the program is concerned, all cars are the same.