I am new to Python and trying to create a simple phone book with sqlite3. My problem is I have a decorator that changes all strings to lower case, so when I call the displayPerson function, it changes everything to lowercase. My question is can I just return the tuple of attributes from ben.displayPerson into the 'conn.execute insert values' statement, rather than put ben.name, ben.age, ben.phone (which would ignore the decorator).
#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 People():
numofpeeps = 0
def __init__(self, name, age, phone, fblink):
self.name=name
self.age=age
self.phone=phone
self.fblink=fblink
People.numofpeeps += 1
@lowercasewrapper
def displayPerson(self):
return self.name, self.age, self.phone, self.fblink
ben=People("bEn", "10 years old", "503-405-4021", "http://facebook.com/ben")
#sqlite section
import sqlite3
conn = sqlite3.connect('addressbook.db')
cur=conn.cursor()
conn.execute('''
CREATE TABLE people(name TEXT,
age TEXT, phone TEXT, fblink TEXT)''')
conn.execute("insert into people values (?, ?, ?, ?)", (ben.displayPerson))
cur.close()
conn.commit()
conn.close()
The error I'm getting in the python interpreter says:
line 33, in <module>
conn.execute("insert into people values (?, ?, ?, ?)", (ben.displayPerson))
ValueError: parameters are of unsupported type
Note: This works if I do conn.execute ("insert into people values (?, ?, ?, ?)", (ben.name, ben.age, ben.phone))
But, I want to use the decorator beforehand and I can't figure out how to do that.