Bu benim kodum. Ben db veri seçmek ve bu sınıf nesne olarak ayarlamak istiyorum.python string'e değer katın
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)
Bu çizgi yanlıştır:
"t" . str(row[4]) = Parish (row[0], row[1], row[2])
ben böyle bir şey yapmak istiyorum:
t1
t2
t3
Bunu nasıl düzenlemeniz gerekir? Divv sütununa karşılık gelen satır [4] tamsayıdır.
kodunuzun çıktısı bu da benim için: 't [str (satır [4])] = Parish (satır [0], satır [1], sıra [2 ]) IndexError: tuple endeksi aralık dışı – niloofar