Unwritten Rules
PI = 3.14
suggests that PI
is a constant value. However, this is just a convention and doesn't prevent the variable from being altered at runtime.PI = 3.14
suggests that PI
is a constant value. However, this is just a convention and doesn't prevent the variable from being altered at runtime.Copy Codefrom dataclasses import dataclass
@dataclass(frozen=True)
class Constants:
PI: float = 3.14159
MAX_CONNECTIONS: int = 100
pip install pconst
and then define constants like so:Copy Codefrom pconst import const
const.PI = 3.14159
const.MAX_CONNECTIONS = 100
Copy CodeDEFAULT_DB_PATH = "/path/to/database.sqlite"
def connect_to_db(path=DEFAULT_DB_PATH):
# Connection logic here
pass
Copy CodeCONFIG = {
'MAX_USERS': 10,
'TIMEOUT': 300
}
def configure_app(config=CONFIG):
# Apply configuration
pass