Databases, Tkinter, debugging and web basics
SQLite database access
sqlite3 is included with Python. Always use parameterized queries rather than string concatenation with untrusted input.
import sqlite3
with sqlite3.connect(":memory:") as db:
db.execute("CREATE TABLE tasks (name TEXT)")
db.execute("INSERT INTO tasks VALUES (?)", ("study",))
print(db.execute("SELECT * FROM tasks").fetchall())Tkinter GUI
Tkinter is a standard GUI toolkit available with many Python distributions; some Linux installations require an additional OS package.
import tkinter as tk
root = tk.Tk()
root.title("Training")
tk.Label(root, text="Hello Python").pack(padx=20, pady=20)
root.mainloop()Debugging and testing
Use breakpoints, a debugger and assertions. Test normal cases and edge cases.
def double(x):
return x * 2
assert double(3) == 6
breakpoint()Python and the web
CGI scripts are historically relevant but deprecated and removed from Python 3.13. Modern web services typically use frameworks and WSGI/ASGI servers. Network scripting can use urllib or socket.
from urllib.request import urlopen
# Only fetch URLs you trust and can access.
# with urlopen("https://example.org", timeout=5) as r:
# print(r.status)TOSA-style final assessment
Practice a short end-to-end project: read a CSV or text file, validate values, compute a summary, store results in SQLite, and present the results in the console or a small GUI. The supplied syllabus mentions TOSA certification; this guide is not an official TOSA exam.