Where did the databases come from in this video?
I am confused how our current file (diary.py) contains the other files in our current workspace. I.e. - when we do ls after typing python diary.py, why do queries.py, students.db and students.py show? I see no mention of those files in our diary.py 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(default=datetime.datetime.now) class Meta: database = db def initailize(): """Create the database and table if they don't exist""" db.connect() 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__': menu_loop()
Cheo R37,145 Points
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')