I need to query the table, and create an instance of a class Car for each row in the database. I have reached to this point, but I am getting an error
return [Car(*row) for row in rows] TypeError: init() takes 1 positional argument but 7 were given... There are 6 attributes to the cars table...oy vey!
import sqlite3 as lite
def db_connect():
con = lite.connect('ins.sqlite')
with con:
cur = con.cursor()
cur.execute('select * from cars;')
rows = cur.fetchall()
for row in rows:
#return (row) #Use list comprehension to get all rows
return [Car(*row) for row in rows]
class Car:
def car_info(self):
'Add all the necessary methods and properties you want'
a = db_connect()
return a
def __init__(self, **kwargs):
self.variables = kwargs
def main():
x = Car() #Create a Object x
a = x.car_info()
ok = tuple(map(str, a)) #convert float data into string
print ('Make Model Model Displacement
Power Luxury')
print (' '.join(ok))
main()