mirror of
https://github.com/python/cpython.git
synced 2025-08-08 02:48:55 +00:00
bpo-44106: Improve sqlite3 example database contents (GH-26027)
This commit is contained in:
parent
9014437573
commit
92d1064727
9 changed files with 37 additions and 42 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue