Re: singleton ... again

2014-02-13 Thread Piet van Oostrum
Ben Finney ben+pyt...@benfinney.id.au writes: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never really seen the point of in Python, or any other language for that

Re: singleton ... again

2014-02-13 Thread Ned Batchelder
On 2/13/14 4:00 AM, Piet van Oostrum wrote: Ben Finney ben+pyt...@benfinney.id.au writes: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never really seen the point of in

Re: singleton ... again

2014-02-13 Thread Chris Angelico
On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder n...@nedbatchelder.com wrote: I still don't see it. To convince me that a singleton class makes sense, you'd have to explain why by virtue of the class's very nature, it never makes sense for there ever to be more than one of them. There's a

Re: singleton ... again

2014-02-13 Thread Roy Smith
In article mailman.6834.1392292646.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder n...@nedbatchelder.com wrote: I still don't see it. To convince me that a singleton class makes sense, you'd have to explain why by

Re: singleton ... again

2014-02-13 Thread Ethan Furman
On 02/13/2014 03:50 AM, Ned Batchelder wrote: On 2/13/14 4:00 AM, Piet van Oostrum wrote: Ben Finney ben+pyt...@benfinney.id.au writes: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern.

Re: singleton ... again

2014-02-13 Thread Roy Smith
In article mailman.6850.1392313443.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: Say you have a class that represents serial ports or your computer. You should get the same object every time you ask for SerialPort(2). Why? Certainly, you should get objects which

Re: singleton ... again

2014-02-13 Thread Ethan Furman
On 02/13/2014 09:57 AM, Roy Smith wrote: In article mailman.6850.1392313443.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: Say you have a class that represents serial ports or your computer. You should get the same object every time you ask for SerialPort(2). Why?

Re: singleton ... again

2014-02-13 Thread Roy Smith
In article mailman.6852.1392317509.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: On 02/13/2014 09:57 AM, Roy Smith wrote: In article mailman.6850.1392313443.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: Say you have a class that represents

Re: singleton ... again

2014-02-13 Thread Tim Delaney
On 13 February 2014 20:00, Piet van Oostrum p...@vanoostrum.org wrote: Ben Finney ben+pyt...@benfinney.id.au writes: Make that “somewhere” a module namespace, and you effectively have a Singleton for all practical purposes. So yes, I see the point of it; but we already have it built in :-)

Re: singleton ... again

2014-02-13 Thread Chris Angelico
On Fri, Feb 14, 2014 at 6:03 AM, Roy Smith r...@panix.com wrote: In article mailman.6852.1392317509.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: You mean use the Borg pattern instead of the Singleton pattern? As far as I can tell they are two shades of the same

Re: singleton ... again

2014-02-13 Thread Chris Angelico
On Fri, Feb 14, 2014 at 2:24 AM, Roy Smith r...@panix.com wrote: In article mailman.6834.1392292646.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder n...@nedbatchelder.com wrote: I still don't see it. To convince me that

Re: singleton ... again

2014-02-13 Thread Robert Kern
On 2014-02-13 20:03, Chris Angelico wrote: On Fri, Feb 14, 2014 at 2:24 AM, Roy Smith r...@panix.com wrote: In article mailman.6834.1392292646.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder n...@nedbatchelder.com wrote:

Re: singleton ... again

2014-02-13 Thread Chris Angelico
On Fri, Feb 14, 2014 at 8:13 AM, Robert Kern robert.k...@gmail.com wrote: We don't use `is None` instead of `== None` for the speed. We use it for robustness. We don't want arbitrary __eq__()s to interfere with our sentinel tests. If None weren't a singleton that we could use as such a

Re: singleton ... again

2014-02-13 Thread Grant Edwards
On 2014-02-13, Roy Smith r...@panix.com wrote: I envision SerialPort being a thin layer on top of a bunch of OS-specific system calls to give them a pythonic interface. Yep, that's pretty much what pyserial is http://pyserial.sourceforge.net/ Things like is_shutdown() and set_bit_rate()

Re: singleton ... again

2014-02-13 Thread Gregory Ewing
Steven D'Aprano wrote: On Wed, 12 Feb 2014 23:04:32 +1300, Gregory Ewing wrote: If you really want to make sure nobody creates another instance by accident, delete the class out of the namespace after instantiating it. That does not work. It is trivial to get the type from an instance: I

Re: singleton ... again

2014-02-13 Thread Gregory Ewing
Steven D'Aprano wrote: Of course it can happen by accident. It's happened to me, where I've accidentally called NoneType() (which raises, rather than returning a new instance). Well, unlikely to happen by accident, then. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: singleton ... again

2014-02-13 Thread Gregory Ewing
Ethan Furman wrote: Say you have a class that represents serial ports or your computer. You should get the same object every time you ask for SerialPort(2). No, you shouldn't ask for SerialPort(2) at all, you should call get_serial_port(2). Then you won't be fooled into thinking that you're

Re: singleton ... again

2014-02-12 Thread Gregory Ewing
Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never really seen the point of in Python, or any other language for that matter. Just create one instance of the class during initialisation, put it in a global somewhere, and use

Re: singleton ... again

2014-02-12 Thread Ben Finney
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never really seen the point of in Python, or any other language for that matter. Just create one instance of the class

Re: singleton ... again

2014-02-12 Thread Roy Smith
In article mailman.6750.1392199807.18130.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never

Re: singleton ... again

2014-02-12 Thread Asaf Las
On Wednesday, February 12, 2014 7:48:51 AM UTC+2, Dave Angel wrote: Perhaps if you would state your actual goal, we could judge whether this code is an effective way to accomplish it. DaveA Thanks! There is no specific goal, i am in process of building pattern knowledge in python by

Re: singleton ... again

2014-02-12 Thread Asaf Las
There is another one. Once object passes through singletonizator there wont be any other object than first one. Then object constructor can freely be used in every place of code. Curious if there could be any impact and applicability of this to builtin types. p.s. learned today that

Re: singleton ... again

2014-02-12 Thread Asaf Las
mistake, object constructor - to class constructor -- https://mail.python.org/mailman/listinfo/python-list

Re: singleton ... again

2014-02-12 Thread Mark Lawrence
On 12/02/2014 17:50, Asaf Las wrote: On Wednesday, February 12, 2014 7:48:51 AM UTC+2, Dave Angel wrote: Perhaps if you would state your actual goal, we could judge whether this code is an effective way to accomplish it. DaveA Thanks! There is no specific goal, i am in process of

Re: singleton ... again

2014-02-12 Thread Ned Batchelder
On 2/12/14 12:50 PM, Asaf Las wrote: On Wednesday, February 12, 2014 7:48:51 AM UTC+2, Dave Angel wrote: Perhaps if you would state your actual goal, we could judge whether this code is an effective way to accomplish it. DaveA Thanks! There is no specific goal, i am in process of

Re: singleton ... again

2014-02-12 Thread Gregory Ewing
Asaf Las wrote: There is another one. Once object passes through singletonizator there wont be any other object than first one. Then object constructor can freely be used in every place of code. You're still making things far more complicated than they need to be. *Why* do you want to be

Re: singleton ... again

2014-02-12 Thread Michael Torrie
On 02/11/2014 09:34 PM, Asaf Las wrote: playing a bit with subject. pros and cons of this approach? did i create bicycle again? :-) I always thought sticking an object in a module is the simplest form of singleton. -- https://mail.python.org/mailman/listinfo/python-list

Re: singleton ... again

2014-02-12 Thread Tim Delaney
On 13 February 2014 08:34, Ned Batchelder n...@nedbatchelder.com wrote: On 2/12/14 12:50 PM, Asaf Las wrote: On Wednesday, February 12, 2014 7:48:51 AM UTC+2, Dave Angel wrote: Perhaps if you would state your actual goal, we could judge whether this code is an effective way to

Re: singleton ... again

2014-02-12 Thread Asaf Las
On Wednesday, February 12, 2014 8:57:09 PM UTC+2, Mark Lawrence wrote: For more data on python patterns search for python+patterns+Alex+Martelli. He's forgotten more on the subject than many people on this list will ever know :) My fellow Pythonistas, ask not what our language can do

Re: singleton ... again

2014-02-12 Thread Asaf Las
On Wednesday, February 12, 2014 11:34:34 PM UTC+2, Ned Batchelder wrote: Not all patterns are useful. Just because it's been enshrined in the GoF patterns book doesn't mean that it's good for Python. Yes, i understand up to some extend usefulness of patterns. i did not read the GoF book.

Re: singleton ... again

2014-02-12 Thread Asaf Las
On Wednesday, February 12, 2014 11:57:02 PM UTC+2, Gregory Ewing wrote: If you want to hide the distinction between using call syntax and just accessing a global, then export a function that returns the global instance. That function can even lazily create the instance the first time it's

Re: singleton ... again

2014-02-12 Thread Roy Smith
In article 9785668d-6bea-4382-8a0c-c1258f2e2...@googlegroups.com, Asaf Las roeg...@gmail.com wrote: On Wednesday, February 12, 2014 7:48:51 AM UTC+2, Dave Angel wrote: Perhaps if you would state your actual goal, we could judge whether this code is an effective way to accomplish it.

Re: singleton ... again

2014-02-12 Thread Steven D'Aprano
On Wed, 12 Feb 2014 23:04:32 +1300, Gregory Ewing wrote: Roy Smith wrote: It looks to me like he's trying to implement a classic Gang of Four singleton pattern. Which I've never really seen the point of in Python, or any other language for that matter. Just create one instance of the class

Re: singleton ... again

2014-02-12 Thread Ben Finney
Steven D'Aprano st...@pearwood.info writes: On Wed, 12 Feb 2014 23:04:32 +1300, Gregory Ewing wrote: If you really want to make sure nobody creates another instance by accident, delete the class out of the namespace after instantiating it. That does not work. It is trivial to get the

Re: singleton ... again

2014-02-12 Thread Steven D'Aprano
On Thu, 13 Feb 2014 14:07:55 +1100, Ben Finney wrote: Steven D'Aprano st...@pearwood.info writes: On Wed, 12 Feb 2014 23:04:32 +1300, Gregory Ewing wrote: If you really want to make sure nobody creates another instance by accident, delete the class out of the namespace after instantiating

Re: singleton ... again

2014-02-12 Thread Chris Angelico
On Thu, Feb 13, 2014 at 3:24 PM, Steven D'Aprano st...@pearwood.info wrote: Of course it can happen by accident. It's happened to me, where I've accidentally called NoneType() (which raises, rather than returning a new instance). It does in 2.7, yes, but not in 3.4: type(None)() is None True

Re: singleton ... again

2014-02-11 Thread Asaf Las
there is error should assign weakref to class static member otherwise __del__ will never be called. -- https://mail.python.org/mailman/listinfo/python-list

Re: singleton ... again

2014-02-11 Thread Roy Smith
In article mailman.6728.1392183929.18130.python-l...@python.org, Dave Angel da...@davea.name wrote: Asaf Las roeg...@gmail.com Wrote in message: playing a bit with subject. pros and cons of this approach? did i create bicycle again? :-) class myclass(object): class_instance