Answer the question
In order to leave comments, you need to log in
Is it possible to get a SQLite database string as a dictionary?
I'm trying to make a small SQLite application using the DB API.
The manual says something like this:
>>> for row in cur.execute('SELECT * FROM stocks ORDER BY price'):
print(row)
('2006-01-05', 'BUY', 'RHAT', 100, 35.14)
('2006-03-28', 'BUY', 'IBM', 1000, 45.0)
('2006-04-06', 'SELL', 'IBM', 500, 53.0)
('2006-04-05', 'BUY', 'MSFT', 1000, 72.0)
Answer the question
In order to leave comments, you need to log in
1. https://docs.python.org/3/library/sqlite3.html#sql...
2. https://docs.python.org/3/library/sqlite3.html#sql...
con = sqlite3.connect("localhost")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute('SELECT * FROM stocks ORDER BY price')
r = cur.fetchone()
print(r['price'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question