One technique i use is a local variable in a module as the class, with a factory function to create or provide the reference to the instance
Code:
instance = None
def GetSingleInstance():
if instance is None:
instance = MyClass()
return instance
class MyClass():
def __init(self)__:
pass
def do_stuff():
pass
This way although effectively you have a global, it is hidden behind a factory function, and the factory function is the thing that is in global scope : as "module.GetSingleInstance() - just need to make sure that all of your code calls the factory function.
You can extend this to provide things like names against objects, so you can refer to an object with a string (or number) - basically the factory function maintains the dictionary.
Bookmarks