implementing singleton class at the module level

  • Thread starter Satchidanand Haridas
  • Start date
S

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,219
Messages
2,571,118
Members
47,737
Latest member
CarleyHarm

Latest Threads

Top