Thanks for pointing out the mistake!<div>Works.<br clear="all">- Saqib<br><br><br>
<br><br><div class="gmail_quote">On Thu, Dec 22, 2011 at 4:31 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">Saqib Ali wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
MYCLASS.PY:<br>
<br>
#!/usr/bin/env python<br>
import os, sys, string, time, re, subprocess<br>
import Singleton<br>
</blockquote>
<br></div>
This should be 'from Singleton import Singleton'<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
@Singleton<br>
class myClass:<br>
        def __init__(self):<br>
        print 'Constructing myClass'<br>
</blockquote>
<br></div>
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.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
    def __del__(self):<br>
        print 'Destructing myClass'<br>
<br>
<br>
</blockquote></div>
> class Singleton:<br>
><br>
>     def __init__(self, decorated):<br>
>         self._decorated = decorated<br>
><br>
>     def Instance(self):<br>
>         try:<br>
>             return self._instance<br>
>         except AttributeError:<br>
>             self._instance = self._decorated()<br>
>             return self._instance<br>
><br>
>     def __call__(self):<br>
>         raise TypeError(<br>
>             'Singletons must be accessed through the `Instance`<br>
> method.')<br><font color="#888888">
<br>
<br>
~Ethan~<br>
</font></blockquote></div><br></div>