I'm playing around with sqlite3, and when I say playing around, I mean I have no idea how to use it. Is con.execute what you use to actually save things into the database? How do I move george=people at the bottom of this example into sql?
Any help or pointers in the right direction would be appreciated.
#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()