~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Doc/includes/sqlite3/execsql_fetchonerow.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

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