callable classes

Duncan Smith buzzard at urubu.freeserve.co.uk
Mon Dec 29 17:02:50 CET 2003


"Terry Reedy" <tjreedy at udel.edu> wrote in message
news:_bydnV23friKY3CiRVn-gQ at comcast.com...
>
> "Duncan Smith" <buzzard at urubu.freeserve.co.uk> wrote in message
> news:bskkig$sf6$1 at news7.svr.pol.co.uk...
> > > What do you mean by 'callable class'? Classes are callables. Ot you
> mean
> > >   a class that defines __call__ method? In this case it's really
> useful.
> > >
> > > regards,
> > > anton.
> >
> > Yes, I meant a class that defines a __call__ method.  Cheers.
>
> Which makes the *instances* callable, so you meant 'class with callable
> instances'.
>
> TJR
>

Yes.  From what I can gather from reverse engineering other's code is that
the approach I am investigating is to create a single (global) callable
instance when the module is imported.  Something like,

pointwise_operation = pointwise_operation()

Then in the class where I originally had the pointwise methods I need
something like, e.g.,

def __mul__(self, other): return pointwise_operation.multiply(self, other)

I'm just not clear what the advantages / disadvantages are over just leaving
all the pointwise operation methods in the original class.  BTW it first
occurred to me to do this after reading Numeric's MA.py.

Duncan





More information about the Python-list mailing list