import sqlite3
conn = sqlite3.connect('db.db')
c = conn.cursor()
def log_in(patient):
with conn:
c.execute("""INSERT INTO patient_office_syndrome VALUES
(?, ?, ?, ?, ?, ?, ?, ?)""", (patient.Personal_id,patient.first_name, patient.last_name, patient.age, patient.phone, patient.gender, patient.weight, patient.height))
patient_1 = ('1409903748846541','siri','pat','25','06119433332',0,'80','190')
log_in(patient_1)
conn.commit()
conn.close()
Traceback (most recent call last): File "c:\Users\User\Desktop\db_and_admin_web\main.py", line 19, in log_in(patient_1) File "c:\Users\User\Desktop\db_and_admin_web\main.py", line 11, in log_in (?, ?, ?, ?, ?, ?, ?, ?)""", (patient.Personal_id,patient.first_name, patient.last_name, patient.age, patient.phone, patient.gender, patient.weight, patient.height)) AttributeError: 'tuple' object has no attribute 'Personal_id'
1条答案
按热度按时间hyrbngr71#
patient
的类型是什么?您问题中的语法暗示您要使用namedtuple
。例如,将
patient
定义为:然后这样使用它:
或者(可能更简单),可以将
patient
实现为dict。