January 2019
Beginner
318 pages
8h 23m
English
Now, we are going to retrieve the data from the table. For that, create a retrieve_data.py script and write the following content in it:
import sqlite3con_obj = sqlite3.connect('test.db')cur_obj = con_obj.execute("SELECT title, author from books")for row in cur_obj: print ("Title = ", row[0]) print ("Author = ", row[1], "\n")con_obj.close()
Run the script and you will get the output as follows:
student@ubuntu:~/work$ python3 retrieve_data.pyOutput:Title = Pride and PrejudiceAuthor = Jane Austen Title = Harry PotterAuthor = J.K Rowling Title = The Lord of the RingsAuthor = J. R. R. Tolkien Title = Murder on the Orient ExpressAuthor = Agatha Christie Title = A Study in ScarletAuthor = Arthur Conan Doyle
In the preceding ...
Read now
Unlock full access