In Python, a static field is usually called a class attribute: data defined on the class and shared by its instances. Use it when every instance should refer to the same value, rather than storing duplicate instance attributes. Place class attributes immediately below the class definition and above __init__ so their shared role is clear. section 8.1.4
class Task:
user = "the logged in user"
def __init__(self, title, desc, urgency):
pass
Store the logged-in user once on Task instead of accepting and storing it separately for every task instance. section 8.1.4
Choose a class attribute when:
- All instances share the same value, such as the user creating every task. section 8.1.4
- A shared resource belongs to the class, such as a database connection used by Task operations. section 14.3.1
- You need named constants, but recognize that ordinary class attributes do not create true enumeration members or support enumeration iteration. section 9.1.1 section 9.1.2
Shared task data
A Task class can expose a class-level user or database connection while keeping title, description, and urgency as per-instance attributes. For database-backed tasks, create_sqlite_database assigns the connection through cls.con and later operations reuse it. section 8.1.4 section 14.3.1
Listing 9.1 Implementing an enumeration class
from enum import Enum class Direction(Enum): NORTH = 0 SOUTH = 1 EAST = 2 WEST = 3
Use Enum when named constants should become discrete members rather than unrelated integer-valued class attributes. section 9.1.2






