How does Mr. Martelli's Borg recipe work ?

Ian Bicking ianb at
Wed Jul 23 05:19:16 CEST 2003

On Tue, 2003-07-22 at 20:37, Mars wrote:
> I have looked long and hard at Mr. Martelli's Borg recipe:
> It is a very useful substitute for a Singleton, but I can't figure out
> how it works. 

While I don't want to discourage you from learning more about the
internals of Python objects (certainly a worthwhile goal), "singletons"
are usually thought about too hard by people new to Python.  This is a
good way to make a singleton:

class _Something:

TheSomething = _Something()

Then just never refer to _Something again.  Import TheSomething (calling
it whatever you want), and use it, not its class.  It's a singleton
because there's only one of them.  Simplicity!


More information about the Python-list mailing list