Re: singleton objects with decorators

2005-04-12 Thread Steven Bethard
James Stroud wrote: Other than using modules, I thought @classmethod took care of this kind of need: class SingleThing: some_values = {"fanciness":0} def __init__(self): raise Exception, "not enough preceding stars to be fancy enough" @classmethod def why_so_fancy(self): print "wh

Re: singleton objects with decorators

2005-04-12 Thread James Stroud
Other than using modules, I thought @classmethod took care of this kind of need: class SingleThing: some_values = {"fanciness":0} def __init__(self): raise Exception, "not enough preceding stars to be fancy enough" @classmethod def why_so_fancy(self): print "why make every thing s

Re: singleton objects with decorators

2005-04-12 Thread Bengt Richter
On 12 Apr 2005 08:00:42 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >I did not put memoize on __new__. I put it on the metaclass __call__. >Here is my memoize: > > def memoize(func): > memoize_dic = {} > def wrapped_func(*args): > if args in memoize_dic: > ret

Re: singleton objects with decorators

2005-04-12 Thread Steve Holden
Bengt Richter wrote: [...] It's a weird beast, being a subtype of int also. I'll defer to the BDFL in http://www.python.org/peps/pep-0285.html """ The values False and True will be singletons, like None. Because the type has two values, perhaps these should be called "doubletons"? The

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 18:51 pm Michele Simionato wrote: > Uhm? If I pass different parameters I want to have > different instances. The Singleton behaviour is recovered > only when I pass always the same arguments, in > particular when I pass 0-arguments: > class Foobar: > ... __metaclas

Re: singleton objects with decorators

2005-04-12 Thread Michele Simionato
Uhm? If I pass different parameters I want to have different instances. The Singleton behaviour is recovered only when I pass always the same arguments, in particular when I pass 0-arguments: >>> class Foobar: ... __metaclass__ = Memoize ... >>> Foobar() <__main__.Foobar object at 0xb7defbcc>

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 17:00 pm Michele Simionato wrote: > I did not put memoize on __new__. I put it on the metaclass __call__. > Here is my memoize: > > def memoize(func): > memoize_dic = {} > def wrapped_func(*args): > if args in memoize_dic: > return memoize_di

Re: singleton objects with decorators

2005-04-12 Thread Michele Simionato
I did not put memoize on __new__. I put it on the metaclass __call__. Here is my memoize: def memoize(func): memoize_dic = {} def wrapped_func(*args): if args in memoize_dic: return memoize_dic[args] else: result = func(*args) mem

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 17:00 pm Michele Simionato wrote: > I did not put memoize on __new__. I put it on the metaclass __call__. > Here is my memoize: [...] Clever, thanks! :) Ciao Uwe -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton objects with decorators

2005-04-12 Thread Steven Bethard
Uwe Mayer wrote: Tuesday 12 April 2005 10:01 am Steven Bethard wrote: I am using a class to manage configuration settings in an application. This object should only existe once so that when the user changes a setting through a configuration dialog the change imminent in all locations where access t

Re: singleton objects with decorators

2005-04-12 Thread Steven Bethard
Fredrik Lundh wrote: Or if you're using an application object (you should), just add a config object to the application object (app.config.param = ...). Do you have a link or two that describe what you mean by an "application object"? The "you should" comment makes me think this is something of a

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 14:51 pm Michele Simionato wrote: > No. Not everybody knows about Singleton. It is an acquired knowledge. Well, what isn't? What I ment to say, but failed to do so more explicitly, was that it is a term I felt which was generally known to "the programming society". Or that

Re: singleton objects with decorators

2005-04-12 Thread Michele Simionato
Uwe Mayer wrote: > "Singleton" is simple (like the wheel), but that does not make it stupid. > There are two aspects that are important: > > 1. a Singleton has one, very simple property and virtually everyone knows > what you talk about when you explain that you used a "Singleton". In this > case i

Re: singleton objects with decorators

2005-04-12 Thread Bengt Richter
On Tue, 12 Apr 2005 13:26:54 +0200, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> But isn't bool supposed to be a singleton class/type ? >> >> >>> [bool(x) for x in 0, 0.0, [], {}, False] >> [False, False, False, False, False] >> >>> [id(bool(x)) for x in 0, 0.0, [], {}, Fa

Re: singleton objects with decorators

2005-04-12 Thread Fredrik Lundh
Bengt Richter wrote: > But isn't bool supposed to be a singleton class/type ? > > >>> [bool(x) for x in 0, 0.0, [], {}, False] > [False, False, False, False, False] > >>> [id(bool(x)) for x in 0, 0.0, [], {}, False] > [505014288, 505014288, 505014288, 505014288, 505014288] "False" is an ordinary

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 12:09 pm Michele Simionato wrote: > Steven Bethard: >> It strikes me that I've never wanted or needed a singleton object. >> Would you mind sharing your use case? I'm just curious. > > "Singleton" is the most idiotic pattern ever. If you want an instance, > just > instantia

Re: singleton objects with decorators

2005-04-12 Thread Bengt Richter
On 12 Apr 2005 03:09:48 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >Steven Bethard: >> It strikes me that I've never wanted or needed a singleton object. >> Would you mind sharing your use case? I'm just curious. > >"Singleton" is the most idiotic pattern ever. If you want an instance,

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 10:01 am Steven Bethard wrote: >> I am using a class to manage configuration settings in an application. >> This object should only existe once so that when the user >> changes a setting through a configuration dialog the change imminent in >> all locations where access to con

Re: singleton objects with decorators

2005-04-12 Thread Michele Simionato
Steven Bethard: > It strikes me that I've never wanted or needed a singleton object. > Would you mind sharing your use case? I'm just curious. "Singleton" is the most idiotic pattern ever. If you want an instance, just instantiate your class once. If a class should have only one instance, you can

Re: singleton objects with decorators

2005-04-12 Thread Fredrik Lundh
Uwe Mayer wrote: >> It strikes me that I've never wanted or needed a singleton object. >> Would you mind sharing your use case? I'm just curious. > > I am using a class to manage configuration settings in an application. This > object should only existe once so that when the user > changes a sett

Re: singleton objects with decorators

2005-04-12 Thread Reinhold Birkenfeld
Uwe Mayer wrote: > Tuesday 12 April 2005 06:36 am Steven Bethard wrote: >> Uwe Mayer wrote: >>> I've been looking into ways of creating singleton objects. >> >> It strikes me that I've never wanted or needed a singleton object. >> Would you mind sharing your use case? I'm just curious. > > I am

Re: singleton objects with decorators

2005-04-12 Thread Steven Bethard
Uwe Mayer wrote: Tuesday 12 April 2005 06:36 am Steven Bethard wrote: Uwe Mayer wrote: I've been looking into ways of creating singleton objects. It strikes me that I've never wanted or needed a singleton object. Would you mind sharing your use case? I'm just curious. I am using a class to manage

Re: singleton objects with decorators

2005-04-12 Thread Uwe Mayer
Tuesday 12 April 2005 06:36 am Steven Bethard wrote: > Uwe Mayer wrote: >> I've been looking into ways of creating singleton objects. > > It strikes me that I've never wanted or needed a singleton object. > Would you mind sharing your use case? I'm just curious. I am using a class to manage conf

Re: singleton objects with decorators

2005-04-11 Thread Steven Bethard
Uwe Mayer wrote: I've been looking into ways of creating singleton objects. It strikes me that I've never wanted or needed a singleton object. Would you mind sharing your use case? I'm just curious. Thanks, STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton objects with decorators

2005-04-11 Thread Bengt Richter
On Mon, 11 Apr 2005 17:26:09 +0200, Uwe Mayer <[EMAIL PROTECTED]> wrote: >Hi, > >I've been looking into ways of creating singleton objects. With Python2.3 I >usually used a module-level variable and a factory function to implement >singleton objects. > >With Python2.4 I was looking into decorators

Re: singleton objects with decorators

2005-04-11 Thread Steven Bethard
Uwe Mayer wrote: Hi, I've been looking into ways of creating singleton objects. With Python2.3 I usually used a module-level variable and a factory function to implement singleton objects. With Python2.4 I was looking into decorators. The examples from PEP 318 http://www.python.org/peps/pep-0318.ht

singleton objects with decorators

2005-04-11 Thread Uwe Mayer
Hi, I've been looking into ways of creating singleton objects. With Python2.3 I usually used a module-level variable and a factory function to implement singleton objects. With Python2.4 I was looking into decorators. The examples from PEP 318 http://www.python.org/peps/pep-0318.html#examples do