implementing singleton class at the module level

2005-02-10 Thread Satchidanand Haridas
Hi,
I was looking at ways to implement a Singleton class. I saw some methods 
described on the PythonSingleton wiki 
(http://c2.com/cgi/wiki?PythonSingleton). I implemented the following.

code
module: A.py
--
class Singleton:
   def __init__(self):
  #do something
singleton_instance = Singleton()

Then in any other module (eg B.py):
from A import singleton_instance
/code
singleton_instance will be created only once and can be reused in other 
modules. But is this ok? I am trying to figure out what are the 
disadvantages of using the above method. I would appreciate any 
comments. thanks.

regards,
Satchit
--
http://mail.python.org/mailman/listinfo/python-list


Re: implementing singleton class at the module level

2005-02-10 Thread Michele Simionato
A Singleton class is there to be inherited from; a singleton instance
like the one you define is pretty much useless (unless I misunderstand
your intentions).

  Michele Simionato

-- 
http://mail.python.org/mailman/listinfo/python-list