Create a database object Python 3


show more Creating a database object provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Creating a database object

When you are writing an application that uses a database, sometimes it's a good idea to create a class that handles that particular schema. Let's take a look at an example of how you can do that in Python. We'll start by making a working copy of sqlite3-class.py, and we will call it sqlite3-class-working.py, and we'll go ahead and open up that working copy. And here we have a complete working example of a class. It's very simple. It's just a few lines of code, and how we access that class through this interface.

We'll go ahead and run it and you can see what it does. This is just an example of testing this particular class, so it creates a table test and it creates some rows and retrieves the rows. It tests these four functions of the database. So if we look at our interface, we create our object by passing in a file name and a table name, and that will actually initialize the database. And then we create the table using some sql. Then we insert some rows usi...

Creating a database object
Video duration: 7m 0s 6h 36m Beginner

Viewers:

Creating a database object provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Subjects:
Developer Web
Software:
Python
Author:
please wait ...