Code: Alles auswählen
import sqlite3
from idlelib.PyShell import main
from datetime import date, datetime
def main():
db = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
#db = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES)
c = db.cursor()
c.execute('''CREATE TABLE example(id INTEGER PRIMARY KEY, created_at DATE)''')
# Insert a date object into the database
today = date.today()
c.execute('''INSERT INTO example(created_at) VALUES(?)''', (today,))
db.commit()
# Retrieve the inserted object
c.execute('''SELECT created_at FROM example''')
r=sqlite3.Row
row = c.fetchone()
print('The date is {0} and the datatype is {1}'.format(row[0], type(row[0])))
# The date is 2013-04-14 and the datatype is <class 'datetime.date'>
print(row[0])
print(type(row[0]))
print(row[0].isoformat())
print(r.keys())
db.close()
if __name__ == '__main__':
main()
Code: Alles auswählen
Traceback (most recent call last):
File "/home/nor/projects/spielwiese/detect.py", line 32, in <module>
main()
File "/home/nor/projects/spielwiese/detect.py", line 25, in main
print(r.keys())
TypeError: descriptor 'keys' of 'sqlite3.Row' object needs an argument