I have read the Flask documentation and Python documentation to try to understand what these codes do. I know that it is initialise the Database but would like to know in very detail and with normal language, easy language for beginner.
Can anyone please explain me about this?
import sqlite3
from contextlib import closing
DATABASE = 'flaskr.db'
def connect_db():
return sqlite3.connect(app.config[’DATABASE’])
def init_db():
with closing(connect_db()) as db:
with app.open_resource(’schema.sql’, mode=’r’) as f:
db.cursor().executescript(f.read())
db.commit()