Re: singletons

2008-07-20 Thread Aahz
In article <[EMAIL PROTECTED]>, Craig Allen <[EMAIL PROTECTED]> wrote: > >(option 2) >Therefore option two is a family of options where class level members >can be used to share whatever needs to be shared, though strictly the >class is not a singleton since multiple instances are created which >m

Re: singletons

2008-07-18 Thread Craig Allen
On Jul 17, 9:04 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Jul 16, 11:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > > > Hey, forgive me for just diving in, but I have a question I was > > thinking of asking on another list but it really is a general question > > so let me ask it here. It's about

Re: singletons

2008-07-18 Thread Paddy
On Jul 16, 11:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > Hey, forgive me for just diving in, but I have a question I was > thinking of asking on another list but it really is a general question > so let me ask it here.  It's about how to approach making singletons. Hi Craig, This might be goo

Re: singletons

2008-07-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Craig Allen wrote: > On Jul 16, 7:01 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED] > central.gen.new_zealand> wrote: >> >> >>> class TehLibrary(object) : >> >> ... @classmethod >> ... def __new__(self, cls) : >> ... return self >> >> >>> s = TehLibrary(

Re: singletons

2008-07-17 Thread Craig Allen
On Jul 17, 2:15 am, Uwe Schmitt <[EMAIL PROTECTED]> wrote: > On 17 Jul., 00:20, Craig Allen <[EMAIL PROTECTED]> wrote: > > > > > I have several classes in our system which need to act like > > singletons, they are libraries of data classifications, and other such > > libraries of configurations for

Re: singletons

2008-07-17 Thread Uwe Schmitt
On 17 Jul., 00:20, Craig Allen <[EMAIL PROTECTED]> wrote: > > I have several classes in our system which need to act like > singletons, they are libraries of data classifications, and other such > libraries of configurations for the system which need to be global. > ... > > Is it pythonic? My appr

Re: singletons

2008-07-17 Thread Craig Allen
On Jul 16, 7:01 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED] central.gen.new_zealand> wrote: > In message > <[EMAIL PROTECTED]>, Craig > > Allen wrote: > > ... the ideal is still that > > > tl = TehLibrary() would always return the same object. > >> class TehLibrary(object) : > > ... @classmethod

Re: singletons

2008-07-16 Thread Carl Banks
On Jul 16, 6:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > Anyone have any comments?  Is there anything wrong, evil, or ugly > about using a module this way, or am I correct to think that actually, > this is a common approach in python. > > Is it pythonic? The one drawback to this is that it co

Re: singletons

2008-07-16 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Craig Allen wrote: > ... the ideal is still that > > tl = TehLibrary() would always return the same object. >> class TehLibrary(object) : ... @classmethod ... def __new__(self, cls) : ... return self >>> s = TehLibrary() >>> s == TehLibrary() True

Re: singletons

2008-07-16 Thread Asun Friere
On Jul 17, 8:20 am, Craig Allen <[EMAIL PROTECTED]> wrote: > Is it pythonic? You probably can't get anymore pythonic than something written by the BDFL. In describing the use of __new__ in Unifying types and classes in Python 2.2 he gives this recipe for a Singleton. class Singleton(object):

Re: singletons

2008-07-16 Thread Craig Allen
I don't intend to do much subclassing of this, but of course, I'd rather not second guess the future and it's not hard to imagine we will come to some point that we need to do just that. Thanks for the ideas about repairing option one, which I'd given up, though the ideal is still that tl = TehLi

Re: singletons

2008-07-16 Thread castironpi
On Jul 16, 5:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > Hey, forgive me for just diving in, but I have a question I was > thinking of asking on another list but it really is a general question > so let me ask it here.  It's about how to approach making singletons. > Background: I've been progr