テーブルにクエリを実行し、データベースの行ごとに Car クラスのインスタンスを作成する必要があります。ここまでたどり着きましたが、エラーが発生します
return [Car(*row) for row in rows] TypeError: init () は 1 つの位置引数を取りますが、7 つが指定されました... cars テーブルには 6 つの属性があります...オイ ベイ!
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()