Listing 11-02: Query, record by record

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 11\11.02 - Query, record by record.py
# Description: Query, record by record
##############################################################################

import sqlite3
connection = sqlite3.connect("phonebook.db")
cursor = connection.cursor()
cursor.execute("select * from phonebook")
while True:
    result = cursor.fetchone()
    if result is None:
        break
    print(f"Name: {result[0]}\nPhone: {result[1]}")
cursor.close()
connection.close()
Click here to download the file