views:

25

answers:

1

Hello:

Imagine a system (Python) where the different parts constantly interact with one instance of a given object. What is the best way to provide a global access point to this instance?

So far I can only think of building the (Singleton) instance in __init__.py and import the module as needed:

# __init__.py
class Thing(object, Singleton):
 pass

TheThing = Thing()

__all__ = ['TheThing']  

Is there a better way to provide a global access point to TheThing?

Thanks,

J.

+3  A: 

Don't use singletons in python. Python modules are great singletons (they are initialized only once and are available everywhere) and you can have a global variable in one, if you need it.

Here is explanation: http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python

gruszczy
Interesting... let me ponder this.
Arrieta