Getting Started

Get the Lesson Contents Forked

If you’re using GitHub, start by forking the repository.

This creates a copy of the repository under your GitHub account.

You can do this by clicking the “Fork” button at the top right of the repository page.

Clone Lesson Contents to your Machine

This will allow us to clone all the lesson materials required for this chapter into your folder of your choice.

This command should be executed in your terminal after you have git installed.

Python + SQLite Model

lesson#.py

The name of the file can be called anything as long as it has .py extension as we will be writing both of our Python script and SQL queries via SQLite3 within this file

database.db

This file will contain our database that we will be interacting with. Depending on the lessons, the database.db may have a different filename and/or contents

Working Example

lesson1.py

Within lesson 1, we will be exploring a very simple database called pokemon.db that exists within the same directory as the Python file.

For Python to interact with a SQL database using SQLite3, we must do the following operations:

  1. Import sqlite3 (a built-in module within Python)

  1. Create a connection to a database

  1. Create a cursor to interact with the connected database

  1. Commit changes from the connection

  1. Close the cursor & connection when finished

Closing the cursor and connection is important because:

  • it uses up system resources to read/write/append a database -> by closing, we free up such resources

  • it opens up a connection spot -> there are limited number of concurrent connections possible; therefore, releasing a connection means that a new connection can be made

Connected Readings:

  • SQLite3 Documentation from Python (Link)

Last updated