On 3/4/2010 10:32 PM, Steven D'Aprano wrote:
Python does have it's own singletons, like None, True and False.
True and False are not singletons.
For some reason, they behave quite differently:
Because they are quite different.
NoneType fails if you try to instantiate it again,
Because
On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote:
On 3/4/2010 10:32 PM, Steven D'Aprano wrote:
Python does have it's own singletons, like None, True and False.
True and False are not singletons.
Duotons? Doubletons?
t1 = bool(1)
t2 = bool(1)
t1 is t2
True
t1 is t2 is bool(this
On 3/5/2010 1:01 PM, Steven D'Aprano wrote:
On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote:
On 3/4/2010 10:32 PM, Steven D'Aprano wrote:
Python does have it's own singletons, like None, True and False.
True and False are not singletons.
Duotons? Doubletons?
The latter is what I
On Fri, 05 Mar 2010 16:25:46 -0500, Terry Reedy wrote:
On 3/5/2010 1:01 PM, Steven D'Aprano wrote:
On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote:
On 3/4/2010 10:32 PM, Steven D'Aprano wrote:
Python does have it's own singletons, like None, True and False.
True and False are not
I think the important difference between None and booleans
wrt singleton behaviour is that things are often compared
with None using is, so it's quite important that there
only be one instance of NoneType around, and it makes
sense not to give people the false impression that they
can create
Steven D'Aprano wrote:
While Doubleton or even Tripleton sound cute, once you get to large
counts it all starts getting ugly and horrible. Polyton? Blah.
Tupleton?
--
Greg
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
Groan. What is it with the Singleton design pattern? It is one of the
least useful design patterns, and yet it's *everywhere* in Java and C++
world.
It's useful when larking about in language internals for learning
purposes, for instance. I don't recall ever actually
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:
On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote:
Hello,
So I set out to write generic singleton, i.e. the one that would do a
singleton with attributes of specified class. At first:
Groan. What is it with the Singleton design
Duncan Booth duncan.bo...@invalid.invalid writes:
It is also *everywhere* in the Python world. Unlike Java and C++, Python
even has its own built-in type for singletons.
If you want a singleton in Python use a module.
So the OP's original examples become:
--- file singleton.py ---
foo =
On Thu, 04 Mar 2010 12:21:26 +, Duncan Booth wrote:
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:
On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote:
Hello,
So I set out to write generic singleton, i.e. the one that would do a
singleton with attributes of specified class
On Mar 4, 7:32 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
Python does have it's own singletons, like None, True and False. For some
reason, they behave quite differently: NoneType fails if you try to
instantiate it again, while bool returns the appropriate existing
mk wrote:
Or I could make my life simpler and use global variable. :-)
Indeed. You actually *have* a global variable already, you've
just hidden it inside another object. That doesn't make it any
less global, though.
If you want to defer creation of the object until the first
time it's used,
Hello,
So I set out to write generic singleton, i.e. the one that would do a
singleton with attributes of specified class. At first:
class Singleton(object):
instance = None
def __new__(cls, impclass, *args, **kwargs):
if cls.instance is None:
cls.instance
mk mrk...@gmail.com writes:
[...]
hashable
..
All of Python’s immutable built-in objects are hashable, while no
mutable containers (such as lists or dictionaries) are.
Well ok, hashable they're not; but apparently at least dict and list
have id()?
lists and dicts are not hashable, but
Arnaud Delobelle wrote:
mk mrk...@gmail.com writes:
[...]
hashable
..
All of Python’s immutable built-in objects are hashable, while no
mutable containers (such as lists or dictionaries) are.
Well ok, hashable they're not; but apparently at least dict and list
have id()?
lists and dicts
On Wed, Mar 3, 2010 at 1:11 PM, mk mrk...@gmail.com wrote:
Or I could make my life simpler and use global variable. :-)
Ding ding ding!
90% of Design Patterns is making Java suck less.
Other languages don't necessarily suffer from Java's design flaws.
--
Jonathan Gardner
mk a écrit :
does every builtin class have unique id?
Classes are objects. And every object *within a python process* has it's
own unique id. For a definition of unique being unique amongst the
objects living in the process at a given time - IOW, if an object is
garbage-collected, it's id can
On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote:
Hello,
So I set out to write generic singleton, i.e. the one that would do a
singleton with attributes of specified class. At first:
Groan. What is it with the Singleton design pattern? It is one of the
least useful design patterns, and yet
On Wed, Mar 3, 2010 at 5:18 PM, Jonathan Gardner
jgard...@jonathangardner.net wrote:
On Wed, Mar 3, 2010 at 1:11 PM, mk mrk...@gmail.com wrote:
Or I could make my life simpler and use global variable. :-)
Ding ding ding!
90% of Design Patterns is making Java suck less.
Other languages
19 matches
Mail list logo