Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Skip Montanaro
Terry Reedy udel.edu> writes: > > The bug went something like this: > > > > obj = some.default_class > > ... > > if some_other_rare_condition_met: > > ... several lines ... > > obj = some.other_class() > > Should that have been some.other_class (without the ()s?). Ei

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Terry Reedy
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instanc

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > In this particular case it was clearly unnecessary and just obfuscated > the code. I'm wondering, are there some general cases where __call__ > methods of a user-defined class are simply indispensable? I don't know that you couldn't live without __call__, but it would

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Bruno Desthuilliers
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instance

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Skip Montanaro
> > In this case there was a bug. Depending on inputs, sometimes obj > > initialized to a class, sometimes an instance of that class. (I fixed > > that too while I was at it.) The problem was that the use of __call__ > > obscured the underlying bug by making the instance as well as the class > >

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
On Aug 2, 2:30 pm, [EMAIL PROTECTED] wrote: > I'm wondering, are there some general cases where __call__ methods of > a user-defined class are simply indispensable? Indispensable's a strong word, but one thing that entails calling syntax, and can't (reasonably) be done with closures is to override

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
On Aug 2, 4:27 pm, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > In this particular case it was clearly unnecessary and just obfuscated the > > code. I'm wondering, are there some general cases where __call__ methods of > > a user-defined class are simply indispensab

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread James Stroud
James Stroud wrote: > import functools > class enclosable(object): > def __init__(self, func): > self.func = func > def __call__(self, *args, **kwargs): > return functools.partial(self.func, *args, **kwargs) > > For example: > > @enclosable > def do_something_with(a, b): > [etc] O

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread James Stroud
[EMAIL PROTECTED] wrote: > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar, b

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Boddie
Bruno Desthuilliers wrote: > > Most of what you can do with a callable instance can be done with > closures (and is usually done so in FPLs), but given Python's OO nature, > it's sometimes clearer and simpler to use callable instances than > closures. Indeed. I think __call__ has been neglected as

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread infidel
I find it useful in certain situations. In particular, I have used it along with cx_Oracle to provide a python module that dynamically mirrors a package of stored procedures in the database. Basically I had class StoredProcedure(object) and each instance of this class represented a particular sto

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | I'm wondering, are there some general cases where __call__ methods of | a user-defined class are simply indispensable? One classical example (untested, based on memory of posted code): class memoize(): def __init__(self, func):

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > from foo import foo > x = foo(3) > > Or did I miss the point ??? The foo module might define a bunch of additional functions that you still want to be able to access in qualified form. For example it would somewhat clean up the interface to the p

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
Paul Rubin a écrit : > [EMAIL PROTECTED] writes: > >>In this particular case it was clearly unnecessary and just obfuscated the >>code. I'm wondering, are there some general cases where __call__ methods of >>a user-defined class are simply indispensable? > > > I don't know about "indispensable"

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Rubin
[EMAIL PROTECTED] writes: > In this particular case it was clearly unnecessary and just obfuscated the > code. I'm wondering, are there some general cases where __call__ methods of > a user-defined class are simply indispensable? I don't know about "indispensable" but __call__ is convenient somet

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar,

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Chris Mellon
On 8/2/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I don't personally use __call__ methods in my classes, but I > > have encountered it every now and then here at work in code > > written by other people. The other day I replaced __

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Neil Cerutti
On 2007-08-02, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> I don't personally use __call__ methods in my classes, but I >> have encountered it every now and then here at work in code >> written by other people. The other day I replaced _

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Neil Cerutti
On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I don't personally use __call__ methods in my classes, but I > have encountered it every now and then here at work in code > written by other people. The other day I replaced __call__ > with a more obvious method name, so now instead of

Re: __call__ in module?

2005-09-27 Thread ncf
Thanks for this information. It'd really be interesting to see how well this works for the code I wish to apply it to. Thanks again and have a GREAT day. -Wes -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__ in module?

2005-09-27 Thread ncf
My thanks to you and Fredrik Lundh for the quality replies. however much so, I appreciate your moreso descriptive reply. I probably should've been a little more specific in my original query, and have stated that I *did* try it before I posted here asking for help. I was just hoping somebody would

Re: __call__ in module?

2005-09-27 Thread ncf
My thanks to you and Fredrik Lundh for the quality replies. however much so, I appreciate your moreso descriptive reply. I probably should've been a little more specific in my original query, and have stated that I *did* try it before I posted here asking for help. I was just hoping somebody would

Re: __call__ in module?

2005-09-27 Thread Leif K-Brooks
ncf wrote: > I have a feeling that this is highly unlikely, but does anyone in here > know if it's possible to directly call a module, or will I have to wrap > it up in a class? You could use trickery with sys.modules to automatically wrap it in a class: import sys from types import ModuleType c

Re: __call__ in module?

2005-09-27 Thread Steven D'Aprano
On Tue, 27 Sep 2005 14:19:13 -0700, ncf wrote: > I have a feeling that this is highly unlikely, but does anyone in here > know if it's possible to directly call a module, or will I have to wrap > it up in a class? Why not try it yourself? Write a quick module like this: """Call a module""" def

Re: __call__ in module?

2005-09-27 Thread Qopit
Nope - you can't even force it by binding a __call__ method to the module. For future reference, you can check to see what things *are* callable with the built-in function 'callable'. eg (with sys instead of MyApp): >>> import sys >>> callable(sys) False Also - a thing you can do to sort of do

Re: __call__ in module?

2005-09-27 Thread Fredrik Lundh
"ncf" wrote. >I have a feeling that this is highly unlikely, but does anyone in here > know if it's possible to directly call a module no. -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__

2005-05-28 Thread TK
tiissa wrote: > TK wrote: > >> Sorry but it does not work. > > > It _does_ work. It just don't do what you expect. Seems so;-). Thanks a lot for help!!! o-o Thomas -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__

2005-05-28 Thread tiissa
TK wrote: > Sorry but it does not work. It _does_ work. It just don't do what you expect. That's different till you know how to do it. Let's see: > >>> class Test(object): > ... def __call__(self): > ... print 'Hi' > ... You first define a class whose members can be called.

Re: __call__

2005-05-28 Thread Mike Meyer
TK <[EMAIL PROTECTED]> writes: > Simon Percivall wrote: >> Look at http://docs.python.org/ref/callable-types.html >> >class Test(object): >> ... def __call__(self): >> ... print "the instance was called" >> ... >> >t = Test() >t() >> the instance was called >> Is this what y

Re: __call__

2005-05-28 Thread TK
Simon Percivall wrote: > Look at http://docs.python.org/ref/callable-types.html > > class Test(object): > > ... def __call__(self): > ... print "the instance was called" > ... > t = Test() t() > > the instance was called > > Is this what you wanted? Sorry but it does

Re: __call__

2005-05-28 Thread TK
class Test(object): > > ... def __call__(self): > ... print "the instance was called" > ... > t = Test() t() > > the instance was called > > Is this what you wanted? Yeah! Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__

2005-05-28 Thread Simon Percivall
Look at http://docs.python.org/ref/callable-types.html >>> class Test(object): ... def __call__(self): ... print "the instance was called" ... >>> t = Test() >>> t() the instance was called Is this what you wanted? -- http://mail.python.org/mailman/listinfo/python-list