[Tutor] Need info regd Singleton class implementation
Andre Roberge
andre.roberge at gmail.com
Thu Jun 15 12:25:29 CEST 2006
On 6/15/06, Akanksha Govil <govilakanksha at yahoo.com> wrote:
> hi,
>
> I need to implement a singleton class in python.
> Please give me some refernce sites which can help me with the same.
The online Python Cookbook is a good reference site. Here's the
result from a search:
http://aspn.activestate.com/ASPN/search?query=singleton&x=0&y=0§ion=PYTHONCKBK&type=Subsection
I use the following from the printed edition of the Python Cookbook:
class Singleton(object):
"""From the 2nd edition of the Python cookbook.
Ensures that only one instance is created per running script"""
def __new__(cls, *args, **kwargs):
if '_inst' not in vars(cls):
cls._inst = object.__new__(cls, *args, **kwargs)
return cls._inst
André
>
> Also i want to know to call a destructor for a singleton class.
>
> Thanks
> Akanksha
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list