我在玩 sqlite3,当我说玩玩时,我的意思是我不知道如何使用它。con.execute 是您用来将内容实际保存到数据库中的东西吗?如何将本示例底部的 george=people 移动到 sql 中?
任何正确方向的帮助或指示将不胜感激。
#import sqlite3
#
#conn.execute('''CREATE TABLE COMPANY
# (ID INT PRIMARY KEY NOT NULL,
# NAME TEXT NOT NULL,
# AGE INT NOT NULL,
# PHONE CHAR(50),
# FBLINK TEXT NOT NULL)
#
#conn = sqlite3.connect('addressbook.db')
#print "Opened database successfully";
#
#conn.execute("INSERT INTO PHONEBOOK (ID,NAME,AGE,PHONE,FBLINK) \
# VALUES (1, 'Paul', 32, 'California', 20000.00 )");
#
#conn.commit()
#conn.close()
#A decorator to correct uppercase strings
def lowercasewrapper(func):
def wrapper(*args, **kwargs):
return [item.lower() for item in func(*args, **kwargs)]
return wrapper
#Class with object attributes
class People():
numofpeeps = 0
listofpeeps = []
def __init__(self, name, age, phone, fblink):
self.name=name
self.age=age
self.phone=phone
self.fblink=fblink
People.numofpeeps += 1
People.listofpeeps.append(self.name)
@lowercasewrapper #calling the wrapper, to make all strings lowercase
def displayPerson(self):
return self.name, self.age, self.phone, self.fblink
george=People("gEORge", "10 years old", "503-405-4021", "http://facebook.com/boobs")
dave=People("dave", "10", "971-863-3905", "http://boobs.com")
charlie=People("CHARLIE", "19", "823-405-2942", "http://boobs.com")
print george.displayPerson()