Login
You're viewing the assemblag.es public feed.
  • Sep 7, 2024, 3:48 PM

    As a followup to @treyhunner's recent post about using modules as singletons in Python (which I originally encountered from one of @chrisjrn's talks), I sometimes find myself needing to update a global module variable in one of these cases as part of app startup. I've come up with 3 options:

    - Use `global` inside the "init" function
    - Use `globals()['var'] = ` inside the function
    - Use either a single class instance/a class with all `@classmethod`s with module-level aliases ala `random`.

    💬 0🔄 0⭐ 0