blob: 0ca7e14469760b9fde498c9167bb5db320ac5cf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import sqlite3
con = sqlite3.connect("mydb")
cur = con.cursor()
SELECT = "select name, first_appeared from people order by first_appeared, name"
# 1. Iterate over the rows available from the cursor, unpacking the
# resulting sequences to yield their elements (name, first_appeared):
cur.execute(SELECT)
for name, first_appeared in cur:
print(f"The {name} programming language appeared in {first_appeared}.")
# 2. Equivalently:
cur.execute(SELECT)
for row in cur:
print(f"The {row[0]} programming language appeared in {row[1]}.")
con.close()
|