You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
477 B

  1. import sqlite3
  2. con = sqlite3.connect("mydb")
  3. cur = con.cursor()
  4. SELECT = "select name_last, age from people order by age, name_last"
  5. # 1. Iterate over the rows available from the cursor, unpacking the
  6. # resulting sequences to yield their elements (name_last, age):
  7. cur.execute(SELECT)
  8. for (name_last, age) in cur:
  9. print('%s is %d years old.' % (name_last, age))
  10. # 2. Equivalently:
  11. cur.execute(SELECT)
  12. for row in cur:
  13. print('%s is %d years old.' % (row[0], row[1]))