Re: confused about __new__

2011-12-27 Thread Ian Kelly
On Tue, Dec 27, 2011 at 3:19 PM, K Richard Pixley wrote: > Are you trying to demonstrate that I haven't prevented you from > instantiating Foo?  If so, then I will cede that point.  I certainly don't > know enough about python internals just now to even claim to be capable of > protecting a class

Re: confused about __new__

2011-12-27 Thread K Richard Pixley
On 12/27/11 12:34 , Ian Kelly wrote: On Tue, Dec 27, 2011 at 1:31 PM, K Richard Pixley wrote: On 12/27/11 10:28 , Ian Kelly wrote: On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixleywrote: The conceptual leap for me was in recognizing that a class is just an object. The best way, (imo,

Re: confused about __new__

2011-12-27 Thread K Richard Pixley
On 12/27/11 10:28 , Ian Kelly wrote: On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixley wrote: The conceptual leap for me was in recognizing that a class is just an object. The best way, (imo, so far), to create a singleton in python is to use the class itself as the singleton rather than ever

Re: confused about __new__

2011-12-27 Thread Ian Kelly
On Tue, Dec 27, 2011 at 1:31 PM, K Richard Pixley wrote: > On 12/27/11 10:28 , Ian Kelly wrote: >> >> On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixley  wrote: >>> >>> The conceptual leap for me was in recognizing that a class is just an >>> object.  The best way, (imo, so far), to create a singl

Re: confused about __new__

2011-12-27 Thread Ian Kelly
On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixley wrote: > The conceptual leap for me was in recognizing that a class is just an > object.  The best way, (imo, so far), to create a singleton in python is to > use the class itself as the singleton rather than ever instantiating it. >  With a littl

Re: confused about __new__

2011-12-27 Thread Fredrik Tolf
On Tue, 27 Dec 2011, Ian Kelly wrote: On Mon, Dec 26, 2011 at 10:48 PM, Fredrik Tolf wrote: I'm also a bit confused about __new__. I'd very much appreciate it if someone could explain the following aspects of it:  * The manual (<http://docs.python.org/reference/datamodel.html&

Re: confused about __new__

2011-12-27 Thread K Richard Pixley
On 12/26/11 21:48 , Fredrik Tolf wrote: On Mon, 26 Dec 2011, K. Richard Pixley wrote: I don't understand. Can anyone explain? I'm also a bit confused about __new__. I'd very much appreciate it if someone could explain the following aspects of it: * The manual (<http

Re: confused about __new__

2011-12-26 Thread Lie Ryan
On 12/27/2011 04:48 PM, Fredrik Tolf wrote: On Mon, 26 Dec 2011, K. Richard Pixley wrote: I don't understand. Can anyone explain? I'm also a bit confused about __new__. I'd very much appreciate it if someone could explain the following aspects of it: * The manual (<http

Re: confused about __new__

2011-12-26 Thread Ian Kelly
On Mon, Dec 26, 2011 at 10:48 PM, Fredrik Tolf wrote: > I'm also a bit confused about __new__. I'd very much appreciate it if > someone could explain the following aspects of it: > >  * The manual (<http://docs.python.org/reference/datamodel.html>) says >   t

Re: confused about __new__

2011-12-26 Thread Fredrik Tolf
On Mon, 26 Dec 2011, K. Richard Pixley wrote: I don't understand. Can anyone explain? I'm also a bit confused about __new__. I'd very much appreciate it if someone could explain the following aspects of it: * The manual (<http://docs.python.org/reference/datamodel.h

Re: confused about __new__

2011-12-26 Thread K Richard Pixley
On 12/26/11 20:53 , Steven D'Aprano wrote: On Mon, 26 Dec 2011 20:28:26 -0800, K. Richard Pixley wrote: I'm confused about the following. The idea here is that the set of instances of some class are small and finite, so I'd like to create them at class creation time, then hijack __new__ to sim

Re: confused about __new__

2011-12-26 Thread Steven D'Aprano
On Mon, 26 Dec 2011 20:28:26 -0800, K. Richard Pixley wrote: > I'm confused about the following. The idea here is that the set of > instances of some class are small and finite, so I'd like to create them > at class creation time, then hijack __new__ to simply return one of the > preexisting clas

confused about __new__

2011-12-26 Thread K. Richard Pixley
I'm confused about the following. The idea here is that the set of instances of some class are small and finite, so I'd like to create them at class creation time, then hijack __new__ to simply return one of the preexisting classes instead of creating a new one each call. This seems to work i