我没有收到任何错误,但是当我在SQLite中检查我的数据库时。它显示空集。我该怎么办?
我的班级:def __init__ (self):
self.name = ""
self.age = 0
self.weight = 0.0
self.height = 0.0
self.gender = ""
self.email = ""
self.password = "'
def sign_up (self):
self.name = raw_input ("Enter your first Name :")
self.email = raw_input ("Enter A Valid Email id :")
length = int(input ("How long do you want your password to be ? : "))
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
for c in range (length):
self.password += random.choice(chars)
print
print "Your Special Password is :" , self.password
print
self.gender = raw_input ("enter your Gender (male / female) :")
self.age = input ("Enter Your Age :")
self.weight = input ("Enter Your Weight :")
self.height = input ("Enter Your Height :")
print
print "Information Saved..."
print
conn = sqlite3.connect('data.db')
c = conn.cursor()
params = (self.name, self.email, self.password, self.gender, self.age,
self.weight, self.height)
c.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?)", params)
conn.commit()
c.close()
conn.close()
答案 0 :(得分:1)
您正在创建一个用于插入数据的游标,这在sqlite3
:
conn = sqlite3.connect('data.db')
params = (self.name, self.email, self.password, self.gender, self.age,
self.weight, self.height)
conn.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?)", params)
conn.commit()
conn.close()