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
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
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
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
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
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>
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
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
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
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
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
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
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
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
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
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
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,
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
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
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
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
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
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
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
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
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
26 matches
Mail list logo