This is my code. I want to select data from db and set as this class object.
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="me", # your username
passwd="1000", # your password
db="something") # name of the data base
cur = db.cursor()
cur.execute("SELECT img, color, title, divv FROM p_div_gerd WHERE chest = '1'")
class Testing:
def __init__(self, img, color, title):
self.img = img
self.color = color
self.title = title
# print all the first cell of all the rows
for row in cur.fetchall():
"t" . str(row[4]) = Parish (row[0], row[1], row[2])
db.close()
print(t1.img)
print(t1.color)
print(t1.title)
This line is incorrect:
"t" . str(row[4]) = Parish (row[0], row[1], row[2])
I want to have something like:
t1
t2
t3
How should I edit that? row[4] which backs to divv column is integer.