bpo-44106: Improve sqlite3 example database contents (GH-26027)

This commit is contained in:
Erlend Egeberg Aasland 2021-05-19 09:41:19 +02:00 committed by GitHub
parent 9014437573
commit 92d1064727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 42 deletions

View file

@ -3,17 +3,17 @@ import sqlite3
con = sqlite3.connect("mydb")
cur = con.cursor()
SELECT = "select name_last, age from people order by age, name_last"
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_last, age):
# resulting sequences to yield their elements (name, first_appeared):
cur.execute(SELECT)
for (name_last, age) in cur:
print('%s is %d years old.' % (name_last, age))
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('%s is %d years old.' % (row[0], row[1]))
print(f"The {row[0]} programming language appeared in {row[1]}.")
con.close()