Terry Reedy <[EMAIL PROTECTED]> writes:
> Steven D'Aprano wrote:
>
> > And modules aren't callable. I've often thought they should be.
>
> Modules are not callable because their class, module, has no
> __call__ instance method. But (in 3.0, which is all I will check)
> you can subclass module an
Steven D'Aprano wrote:
And modules aren't callable. I've often thought they should be.
Modules are not callable because their class, module, has no __call__
instance method. But (in 3.0, which is all I will check) you can
subclass module and add one.
>>> m = type(__builtins__)
>>> m
>>>
On Sat, 27 Sep 2008 17:41:42 -0400, Terry Reedy wrote:
> In 3.0, at least, one does not need a disk file to create a module.
>
> >>> import types
> >>> me = types.ModuleType('me') # type(__builtins__) works, no import
> >>> me
>
> >>> me.a = 1
> >>> me.a
> 1
> >>> me.a + 1
> 2
Seems to wo
On Sep 27, 6:16 pm, Terry Reedy <[EMAIL PROTECTED]> wrote:
> Aaron "Castironpi" Brady wrote:
> class A(type):
> > ... def __call__( self, *ar ):
> > ... print 'call', self, ar
> > ...
> class B(object):
> > ... __metaclass__= A
> > ...
> B(3)
> > call (3,)
>
> >
Aaron "Castironpi" Brady wrote:
class A(type):
... def __call__( self, *ar ):
... print 'call', self, ar
...
class B(object):
... __metaclass__= A
...
B(3)
call (3,)
Overriding the __call__ method of 'type' has the effect of giving you
a static __call__ method on a cla
Aahz wrote:
In article <[EMAIL PROTECTED]>,
Ben Finney <[EMAIL PROTECTED]> wrote:
Steven D'Aprano <[EMAIL PROTECTED]> writes:
I'd like to be able to call [a class] as if it were a function.
Normally calling a class object returns an instance -- I wish to
return something else.
In that case,
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz)
wrote:
> One cute reason to prefer class singletons to module singletons is that
> subclassing works well for creating multiple singletons. But really,
> the main reason I use class singletons is that they are the absolute
> simplest way t
In article <[EMAIL PROTECTED]>,
Ben Finney <[EMAIL PROTECTED]> wrote:
>Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
>>>
>>> An ordinary singleton is instantiating the class multiple times
>>> yet returning the same instance object; a class singleto
On Sep 27, 5:33 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote:
> > Steven D'Aprano <[EMAIL PROTECTED]> writes:
>
> >> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
> >> > An ordinary singleton is instantiating the class mu
On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>
>> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
>> > An ordinary singleton is instantiating the class multiple times yet
>> > returning the same instance object; a class singleton is simply us
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
> > An ordinary singleton is instantiating the class multiple times
> > yet returning the same instance object; a class singleton is
> > simply using the class directly (like a module).
Where is this "cl
On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote:
>>>
>>> Seems to me that if all the module is used for is to store state,
>>> you're wasting a file on disk. I personal
In article <[EMAIL PROTECTED]>,
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote:
>>
>> Seems to me that if all the module is used for is to store state, you're
>> wasting a file on disk. I personally prefer to use a class singleton.
>
>I don't recognise
On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote:
> Seems to me that if all the module is used for is to store state, you're
> wasting a file on disk. I personally prefer to use a class singleton.
I don't recognise the term "class singleton". Can you explain please? How
is it different from an or
In article <[EMAIL PROTECTED]>,
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>On 21 Sep 2008 22:39:47 GMT, Steven D'Aprano
><[EMAIL PROTECTED]> declaimed the following in
>comp.lang.python:
>>
>> What do you call such a class?
>
> A wasted definition... The same functionality is achieved by
> > > Usegrammers?
>
usegrammers are just those that use grammars, but misspell it.
--
http://mail.python.org/mailman/listinfo/python-list
> Snce when are "users" ever involved
> in programming problems or programming
> languages ?
>
since the begining, the first users are programmers, users of your
libraries.
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 22, 6:55 pm, MRAB <[EMAIL PROTECTED]> wrote:
> On Sep 22, 11:46 pm, "Aaron \"Castironpi\" Brady"
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
> > cybersource.com.au> wrote:
> > > On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote:
> > > >
On Sep 22, 11:46 pm, "Aaron \"Castironpi\" Brady"
<[EMAIL PROTECTED]> wrote:
> On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
>
>
> cybersource.com.au> wrote:
> > On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote:
> > > On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano
> > >> But that's pr
On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote:
> > On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano
> >> But that's precisely what I want to avoid: I don't want the objects to
> >> share *any* state, not even t
On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote:
> On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano
>> But that's precisely what I want to avoid: I don't want the objects to
>> share *any* state, not even their class. I'm not trying for a Borg or
>> Singleton: the user can call the factory as
On Sep 22, 3:28 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Aaron "Castironpi" Brady a écrit :
>
> > On Sep 22, 2:38 pm, Bruno Desthuilliers
> > <[EMAIL PROTECTED]> wrote:
> (snip)
> >> Going back to robot-mode, Aaron ?
>
> > Not getting the same sense of "soul" as from my usual posts. I
Aaron "Castironpi" Brady a écrit :
On Sep 22, 2:38 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
(snip)
Going back to robot-mode, Aaron ?
Not getting the same sense of "soul" as from my usual posts. I guess
so. Might even drop the name change, too...
Don't !-)
while I'm at it. One
On Sep 22, 2:38 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Aaron "Castironpi" Brady a écrit :
>
>
>
> > On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote:
> >> 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
>
> Sounds to me like a functor, aka a function object:
> http
Aaron "Castironpi" Brady a écrit :
On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote:
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
Sounds to me like a functor, aka a function object:
http://en.wikipedia.org/wiki/Function_object
Ok, then the simple solution is to implement a calla
Steven D'Aprano wrote:
Consider a factory function:
def factory(x): # a toy example
alist = [x]
def foo():
return alist
return foo
Now suppose we "instantiate" the factory (for lack of a better term):
f1 = factory(0)
f2 = factory(0)
Your factory is returning closures
On Sep 21, 3:39 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as
On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote:
> 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
>
> >> Sounds to me like a functor, aka a function object:
> >>http://en.wikipedia.org/wiki/Function_object
>
> > Ok, then the simple solution is to implement a callable type (__call__
> >
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
>> Sounds to me like a functor, aka a function object:
>> http://en.wikipedia.org/wiki/Function_object
>>
>
> Ok, then the simple solution is to implement a callable type (__call__
> method), possibly with appropriate support for the descriptor pr
On 22 Sep, 10:32, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> but it isn't good enough if the function needs to refer to it's own
> state, because functions can only refer to themselves by name and the
> factory can't know what name the function will be bound to.
>
> As far as I know, the only ob
Tim Rowe a écrit :
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
Steven D'Aprano a écrit :
On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote:
Steven D'Aprano a écrit :
I have a class which is not intended to be instantiated. Instead of
using the class to creating an instance
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>:
> Steven D'Aprano a écrit :
>>
>> On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote:
>>
>>> Steven D'Aprano a écrit :
I have a class which is not intended to be instantiated. Instead of
using the class to creating an inst
Steven D'Aprano a écrit :
On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote:
Steven D'Aprano a écrit :
I have a class which is not intended to be instantiated. Instead of
using the class to creating an instance and then operate on it, I use
the class directly, with classmethods. Es
On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano
> But that's precisely what I want to avoid: I don't want the objects to
> share *any* state, not even their class. I'm not trying for a Borg or
> Singleton: the user can call the factory as many times as they want, but
> the objects returned shouldn'
On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote:
> Steven D'Aprano a écrit :
>> I have a class which is not intended to be instantiated. Instead of
>> using the class to creating an instance and then operate on it, I use
>> the class directly, with classmethods. Essentially, the clas
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> I don't want the objects to share state. I'm not exactly sure what I
> said that has given so many people the impression that I do.
This:
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> Essentially, the class is used as a function that keeps state fr
On Mon, 22 Sep 2008 10:12:38 +1000, James Mills wrote:
> On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <[EMAIL PROTECTED]>
> wrote:
>> I call it an obvious misuse and misunderstanding of why you'd use a
>> class in the first place. Either create an instance and not make these
>> things classmet
Steven D'Aprano a écrit :
I have a class which is not intended to be instantiated. Instead of using
the class to creating an instance and then operate on it, I use the class
directly, with classmethods. Essentially, the class is used as a function
that keeps state from one call to the next.
T
On Sep 21, 4:39 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> I have a class which is not intended to be instantiated. Instead of
> using the class to creating an instance and then operate on it, I
> use the class directly, with classmethods. Essentially, the class is
> used as a function that keeps state from on
On Sep 21, 6:05 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Fixing top-posting.
>
> On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:
> > On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
> > <[EMAIL PROTECTED]> wrote:
> >> I have a class which is not intended to be inst
On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <[EMAIL PROTECTED]> wrote:
> I call it an obvious misuse and misunderstanding of why you'd use a class in
> the first place. Either create an instance and not make these things
> classmethods or just share the stuff in a module-level set of variables
Steven D'Aprano:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as a function
> that keeps state from one call to the next.
You may
I call it an obvious misuse and misunderstanding of why you'd use a class in
the first place. Either create an instance and not make these things
classmethods or just share the stuff in a module-level set of variables. But
the instantiating is the best options. Your class attributes might not be
gl
On Mon, Sep 22, 2008 at 9:05 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> I'm not wedded to the idea, there are alternatives (perhaps the factory
> should instantiate the class and return that?) but I assume others have
> used this design and have a name for it.
The problem is, I don't see why
Fixing top-posting.
On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:
> On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>> I have a class which is not intended to be instantiated. Instead of
>> using the class to creating an instance and then operate on it, I us
Hi,
Wouldn't a normal class called State
suffice for storing state between calls ?
And ... Creating a state instance ?
For example:
class State(object):
"""State() -> new state object
Creates a new state object that is suitable
for holding different states of an application.
Usefull
I have a class which is not intended to be instantiated. Instead of using
the class to creating an instance and then operate on it, I use the class
directly, with classmethods. Essentially, the class is used as a function
that keeps state from one call to the next.
The problem is that I don't k
48 matches
Mail list logo