Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17753
| Date | 2011-12-22 13:31 -0800 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Can't I define a decorator in a separate file and import it? |
| References | <53a106b8-1a2f-4b9d-9cac-d6f7dab01696@q11g2000vbq.googlegroups.com> <4EF39C16.4090803@stoneleaf.us> <CA+w+aQ=PsUBZvgVyrpuBk4_kzS7NyMp=Z=zwbPKSsyg1KYp6Rg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3999.1324589276.27778.python-list@python.org> (permalink) |
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~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can't I define a decorator in a separate file and import it? Saqib Ali <saqib.ali.75@gmail.com> - 2011-12-22 12:53 -0800
Re: Can't I define a decorator in a separate file and import it? Saqib Ali <saqib.ali.75@gmail.com> - 2011-12-22 13:09 -0800
Re: Can't I define a decorator in a separate file and import it? Ben Finney <ben+python@benfinney.id.au> - 2011-12-23 09:33 +1100
Re: Can't I define a decorator in a separate file and import it? Andrew Berg <bahamutzero8825@gmail.com> - 2011-12-22 15:20 -0600
Re: Can't I define a decorator in a separate file and import it? Ethan Furman <ethan@stoneleaf.us> - 2011-12-22 13:31 -0800
Re: Can't I define a decorator in a separate file and import it? Ethan Furman <ethan@stoneleaf.us> - 2011-12-22 13:07 -0800
csiph-web