Skip to content

Instantly share code, notes, and snippets.

@daaniam
Created April 4, 2023 06:13
Show Gist options
  • Save daaniam/98eda54d9fc31bd2bac6aece8d61eece to your computer and use it in GitHub Desktop.
Save daaniam/98eda54d9fc31bd2bac6aece8d61eece to your computer and use it in GitHub Desktop.
Basic state class
import json
class TState:
def __new__(cls):
if not hasattr(cls, "instance"):
cls.instance = super(TState, cls).__new__(cls)
return cls.instance
def add(self, name, value):
setattr(self, name, value)
def get(self, name):
return getattr(self, name, None)
def remove(self, name):
delattr(self, name)
def __repr__(self):
return json.dumps(self.__dict__, indent=2, default=str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment