I'm very unsure about this, but my project uses 'convention singletons' (not enforced singletons), that is, if I have a class called DataController
, I define this in the same module:
_data_controller = None
def GetDataController():
global _data_controller
if _data_controller is None:
_data_controller = DataController()
return _data_controller
It is not elegant, since it's a full six lines. But all my singletons use this pattern, and it's at least very explicit (which is pythonic).