Python Using Databases in Python Our Diary App Doing Data Entry

Where did the databases come from in this video?

I am confused how our current file ( contains the other files in our current workspace. I.e. - when we do ls after typing python, why do, students.db and show? I see no mention of those files in our file. See below for the code i am referring to.



import datetime 
from peewee import *

db = SqliteDatabase('diary.db')

class Entry(Model):
    content = TextField()
    timestamp = DateTimeField(

    class Meta:
        database = db

def initailize():
    """Create the database and table if they don't exist"""
    db.create_tables([Entry], safe=True)

def menu_loop():
    """show the menu"""

def add_entry():
    """add an entry"""

def view_entry():
    """view previous entries"""

def delete_entry(entry):
    """Delete and entry"""

if __name__ == '__main__':

1 Answer

Your confusion is one reason why it's discouraged to use the Kleene star to import everything from a package: if it were used in combination with other packages, nobody would know what came from where.

The database comes from the first two lines:

from peewee import *

db = SqliteDatabase('diary.db')

The first one says, import everything from peewee; the second ones creates the database. Here is an example showing it done without everything being imported, simply:

import peewee

db = peewee.SqliteDatabase('test.sqlite')

got it, thanks!