Re: overloading operators for a function object

2011-10-03 Thread Westley Martínez
On Fri, Sep 30, 2011 at 09:50:42PM -0700, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): > def func(): pass > > def __eq__(other): > if other == "check": return True >

Re: overloading operators for a function object

2011-09-30 Thread Chris Rebert
On Fri, Sep 30, 2011 at 9:50 PM, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): >  def func(): pass > >  def __eq__(other): >    if other == "check":  return True >    return False >

overloading operators for a function object

2011-09-30 Thread Fletcher Johnson
Is it possible to overload operators for a function? For instance I would like to do something roughly like... def func_maker(): def func(): pass def __eq__(other): if other == "check": return True return False func.__eq__ = __eq__ return func newfunc = func_maker() newfunc ==

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
On Thu, Oct 16, 2008 at 10:54 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Something that is more pythonic is something that doesn't use > multimethods. It's just an elaborated way to do type checking. In python, > you usually avoid type checking a

Re: Overloading operators

2008-10-16 Thread Lie Ryan
On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I defined. > > > What is the best way to do this? Shall I use a lot of "if...elif" > statements inside the ov

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
Thanks for the suggestion. I think I'm gonna try the multimethods way, that I didn't know about it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading operators

2008-10-15 Thread Kay Schluehr
On 15 Okt., 14:34, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exam

Re: Overloading operators

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 7:34 am, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exa

Re: Overloading operators

2008-10-15 Thread Robert Lehmann
On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For example

Re: Overloading operators

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 7:34 am, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exa

Overloading operators

2008-10-15 Thread Mr . SpOOn
Hi, in a project I'm overloading a lot of comparison and arithmetic operators to make them working with more complex classes that I defined. Sometimes I need a different behavior of the operator depending on the argument. For example, if I compare a object with an int, I get a result, but if I com