Python: thinking of a module and its variables as a singleton — Clean approach?

A common alternative to using a module as a singleton is Alex Martelli’s Borg pattern:

class Borg:
    __shared_state = {}
    def __init__(self):
        self.__dict__ = self.__shared_state
    # and whatever else you want in your class -- that's all!

There can be multiple instances of this class, but they all share the same state.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)