Saqib Ali wrote:
MYCLASS.PY:
#!/usr/bin/env python
import os, sys, string, time, re, subprocess
import Singleton
This should be 'from Singleton import Singleton'
@Singleton
class myClass:
def __init__(self):
print 'Constructing myClass'
At this point, the *instance* of myClass has already been constructed
and it is now being initialized. The __new__ method is where the
instance is actually created.
def __del__(self):
print 'Destructing myClass'
> class Singleton:
>
> def __init__(self, decorated):
> self._decorated = decorated
>
> def Instance(self):
> try:
> return self._instance
> except AttributeError:
> self._instance = self._decorated()
> return self._instance
>
> def __call__(self):
> raise TypeError(
> 'Singletons must be accessed through the `Instance`
> method.')
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list