Created
April 4, 2023 06:13
-
-
Save daaniam/98eda54d9fc31bd2bac6aece8d61eece to your computer and use it in GitHub Desktop.
Basic state class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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