我正在玩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()
答案 0 :(得分:0)
以下是您可以学习的教程:
http://zetcode.com/db/sqlitepythontutorial/
但您可能还想使用ORM为您抽象出数据库详细信息。 ORM将为您提供Python类,您只需编写Python代码而不是数据库代码。