2007-08-15 14:28:22 +00:00
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
con = sqlite3.connect("mydb")
|
|
|
|
|
|
|
|
|
|
cur = con.cursor()
|
2021-05-19 09:41:19 +02:00
|
|
|
SELECT = "select name, first_appeared from people order by first_appeared, name"
|
2007-08-15 14:28:22 +00:00
|
|
|
|
|
|
|
|
# 1. Iterate over the rows available from the cursor, unpacking the
|
2021-05-19 09:41:19 +02:00
|
|
|
# resulting sequences to yield their elements (name, first_appeared):
|
2007-08-15 14:28:22 +00:00
|
|
|
cur.execute(SELECT)
|
2021-05-19 09:41:19 +02:00
|
|
|
for name, first_appeared in cur:
|
|
|
|
|
print(f"The {name} programming language appeared in {first_appeared}.")
|
2007-08-15 14:28:22 +00:00
|
|
|
|
|
|
|
|
# 2. Equivalently:
|
|
|
|
|
cur.execute(SELECT)
|
|
|
|
|
for row in cur:
|
2021-05-19 09:41:19 +02:00
|
|
|
print(f"The {row[0]} programming language appeared in {row[1]}.")
|
2019-05-20 03:22:20 +05:30
|
|
|
|
|
|
|
|
con.close()
|