import os
class Singleton:
"""
单例模式
"""
def __new__(cls, *args, **kwargs):
if not hasattr(cls, "_instance"):
cls._instance = super(Singleton, cls).__new__(cls)
return cls._instance
class Const(Singleton):
"""
单例常量类
"""
class ConstError(TypeError):
pass
class ConstCaseError(ConstError):
pass
def __setattr__(self, name, value):
if name in self.__dict__:
raise self.ConstError(f"can't change const {name}")
self.__dict__[name] = value
const = Const() # 常量实例