Singleton Pattern and Python

hungjunglu at yahoo.com hungjunglu at yahoo.com
Thu Sep 27 17:51:44 EDT 2001


Hi,

I went through old messages in the list and also searched some 
websites, too.

Can someone tell me why not just use a Python module to implement a 
singleton pattern? Or better, why is a Python module not considered a 
singleton? (That is, why no one ever menthioned about it?) I think it 
meets all the requirements, except that it is not really a class per-
se. Am I missing something? Is there a real-life need for singleton 
classes in Python that cannot be fulfilled by using a module?

---------------
#singleton.py
data = 3
def method():
  return 'blah'
---------------
#main.py
import singleton
singleton.data = 4 
singleton.method() 
---------------

thanks,

Hung Jung






More information about the Python-list mailing list