Re: understanding operator overloading

2012-06-01 Thread Chris Rebert
On Fri, Jun 1, 2012 at 9:39 AM, Josh Benner wrote: > > Is there a good way to trace what's going on under the hood wrt operator > overloading? > > I am trying to understand what is happening in the code and output listed > below. > > Why doesn't __getitem__ in my

understanding operator overloading

2012-06-01 Thread Josh Benner
Is there a good way to trace what's going on under the hood wrt operator overloading? I am trying to understand what is happening in the code and output listed below. Why doesn't __getitem__ in mylist return the same result as the builtin list object? Does it have something to do with

Re: help function and operetors overloading

2012-02-05 Thread Terry Reedy
On 2/6/2012 12:48 AM, Mohsen Pahlevanzadeh wrote: Dear all, You know python has many functions for operators overloading such as __add__, __radd__, __invert__, __eq__ and so on. How i see the complete list of them with help function? >>> import operator >>> help(operator

Re: help function and operetors overloading

2012-02-05 Thread Chris Rebert
On Sun, Feb 5, 2012 at 9:48 PM, Mohsen Pahlevanzadeh wrote: > Dear all, > > You know python has many functions for operators overloading such as > __add__, __radd__, __invert__, __eq__ and so on. > How i see the complete list of them with help function? I don't know if there&

help function and operetors overloading

2012-02-05 Thread Mohsen Pahlevanzadeh
Dear all, You know python has many functions for operators overloading such as __add__, __radd__, __invert__, __eq__ and so on. How i see the complete list of them with help function? Yours, Mohsen signature.asc Description: This is a digitally signed message part -- http://mail.python.org

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: python overloading

2011-06-24 Thread Terry Reedy
On 6/24/2011 2:01 PM, anand jeyahar wrote: Not sure, this is the right place, redirect me if it's not. I was curious about the functionoverloading(http://svn.python.org/view/sandbox/trunk/overload/) and was trying to do a svn checkout of the branch and failed. Is it restricted access for even ch

python overloading

2011-06-24 Thread anand jeyahar
Not sure, this is the right place, redirect me if it's not. I was curious about the functionoverloading( http://svn.python.org/view/sandbox/trunk/overload/) and was trying to do a svn checkout of the branch and failed. Is it restricted access for even checkout? How do i get read-only access?

Re: j2py - overloading __init__

2010-10-25 Thread Brendan
On Oct 25, 12:57 pm, Brendan wrote: > I am posting here in the hopes the author of java2python will see it. > Does j2py handle overloading of the __init__ constructor?  For me it > is calling __init__ and not calling the decorator overloaded __init__0. Never mind. Moronic type mistake.

j2py - overloading __init__

2010-10-25 Thread Brendan
I am posting here in the hopes the author of java2python will see it. Does j2py handle overloading of the __init__ constructor? For me it is calling __init__ and not calling the decorator overloaded __init__0. -- http://mail.python.org/mailman/listinfo/python-list

Re: Signature-based Function Overloading in Python

2010-02-27 Thread Michael Rudolf
Am 27.02.2010 10:00, schrieb alex23: Michael Rudolf wrote: In Java, Method Overloading is my best friend Guido wrote a nice article[1] on "multimethods" using decorators, which Ian Bicking followed up on[2] with a non-global approach. 1: http://www.artima.com/weblogs/viewpost.

Re: Signature-based Function Overloading in Python

2010-02-27 Thread alex23
Michael Rudolf wrote: > In Java, Method Overloading is my best friend Guido wrote a nice article[1] on "multimethods" using decorators, which Ian Bicking followed up on[2] with a non-global approach. 1: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 2: http://blog.ianbic

Re: Signature-based Function Overloading in Python

2010-02-25 Thread Bruno Desthuilliers
Michael Rudolf a écrit : (snip) (pseudocode - this is *not* python ;) class Machines (Object): @classmethod def shutdown(cls, Machine, emergency=False): try: if Machine is instanceof(Fileservers): if not emergency: Machine.unmount_raid_first

Re: Signature-based Function Overloading in Python

2010-02-25 Thread Michael Rudolf
Machine.powerswitch.Off() @classmethod def emergency(cls): for machine in cls.instances: cls.shutdown(machine, 1) Other design patterns might me good too, but I like the idea of having emergency protocols in *one* place here. But without m

Re: Signature-based Function Overloading in Python

2010-02-25 Thread Jean-Michel Pichavant
t has its advantages: 1 docstring, 1 way do do it, 1 interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void construct

Re: Signature-based Function Overloading in Python

2010-02-25 Thread Jean-Michel Pichavant
ng, 1 way do do it, 1 interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void constructor(int x) {this.x=x; this.constructor();} and

Re: Signature-based Function Overloading in Python

2010-02-24 Thread Diez B. Roggisch
1 way do do it, 1 interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void constructor(int x) {this.x=x; this.constructor();} and so

Re: Signature-based Function Overloading in Python

2010-02-24 Thread Michael Rudolf
interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void constructor(int x) {this.x=x; this.constructor();} and so on. So most of

Re: Signature-based Function Overloading in Python

2010-02-24 Thread Jean-Michel Pichavant
Michael Rudolf wrote: Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceback (most recent c

Re: Signature-based Function Overloading in Python

2010-02-23 Thread Lie Ryan
On 02/24/10 05:25, Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach in > this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > So - What would be the most pythonic way to emulate this? >

Re: Signature-based Function Overloading in Python

2010-02-23 Thread Arnaud Delobelle
Michael Rudolf writes: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > >>>> def a(): > pass >>>> def a(x): >

Re: Signature-based Function Overloading in Python

2010-02-23 Thread John Posner
On 2/23/2010 1:25 PM, Michael Rudolf wrote: Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceba

Re: Signature-based Function Overloading in Python

2010-02-23 Thread Daniel Fetchinson
> In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): >File "", line 1, in >

Signature-based Function Overloading in Python

2010-02-23 Thread Michael Rudolf
Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceback (most recent call last): File &

Re: Overloading Methods

2009-01-21 Thread "
Chris Rebert wrote: On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: K-Dawg wrote: Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload me

Re: Overloading Methods

2009-01-20 Thread TheFlyingDutchman
> > class Foo(object): > def __init__(self, a, b=10, c=None): > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > Not that it's important to the discussion, but, while Java does not have the capability to give defau

Re: Overloading Methods

2009-01-20 Thread Chris Rebert
(top-posting just for consistency) In that case, you might also be interested in: http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris On Tue, Jan 20, 2009 at 12:19 PM, K-Dawg wrote: > Thank you for the explanation. With my background in Java, I have to get > myself to think a l

Re: Overloading Methods

2009-01-20 Thread K-Dawg
Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> C

Re: Overloading Methods

2009-01-20 Thread Chris Rebert
On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > K-Dawg wrote: >> >> Can you overload methods in Python? >> >> Can I have multiple __inits__ with different parameters passed in? >> > Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload methods in

Re: Overloading Methods

2009-01-20 Thread MRAB
K-Dawg wrote: Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Simple answer: no. -- http://mail.python.org/mailman/listinfo/python-list

Overloading Methods

2009-01-20 Thread K-Dawg
Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Thanks. Kevin -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to run multiple Python processes without overloading CPU or disk i/o

2008-12-08 Thread Philip Semanchuk
On Dec 8, 2008, at 2:48 AM, Gabriel Genellina wrote: En Wed, 03 Dec 2008 02:29:32 -0200, Philip Semanchuk <[EMAIL PROTECTED]> escribió: On Dec 2, 2008, at 11:21 PM, [EMAIL PROTECTED] wrote: Is there a cross-platform way to launch multiple Python processes and monitor CPU usage os.getload

Re: Best way to run multiple Python processes without overloading CPU or disk i/o

2008-12-07 Thread Gabriel Genellina
En Wed, 03 Dec 2008 02:29:32 -0200, Philip Semanchuk <[EMAIL PROTECTED]> escribió: On Dec 2, 2008, at 11:21 PM, [EMAIL PROTECTED] wrote: Is there a cross-platform way to launch multiple Python processes and monitor CPU usage os.getloadavg() might be useful. It certainly works on *nix, don't

Re: Best way to run multiple Python processes without overloading CPU or disk i/o

2008-12-02 Thread Philip Semanchuk
imitations. HTH Philip and disk i/o so that the maximum number of independent processes can be running at all times without overloading their environment? By process I mean independent application sessions vs. multiple threads of a single application. I'm looking for suggestions on what

Best way to run multiple Python processes without overloading CPU or disk i/o

2008-12-02 Thread python
Is there a cross-platform way to launch multiple Python processes and monitor CPU usage and disk i/o so that the maximum number of independent processes can be running at all times without overloading their environment? By process I mean independent application sessions vs. multiple threads of a

Re: overloading for ladder logic

2008-11-07 Thread Aaron Brady
y thought was that this might be able to be completed via > overloading, but I am not sure if (or how) it could be done. > > overloadings: >     + ==> OR >     * ==> AND >     / ==> NOT > > Example original code: >      A=/B+C*D > translates to: >     A=not B

Re: overloading for ladder logic

2008-11-07 Thread Benjamin Kaplan
cation > step. My thought was that this might be able to be completed via > overloading, but I am not sure if (or how) it could be done. > > overloadings: >+ ==> OR >* ==> AND >/ ==> NOT > > Example original code: > A=/B+C*D > tran

Re: overloading for ladder logic

2008-11-07 Thread Paul McGuire
y thought was that this might be able to be completed via > overloading, but I am not sure if (or how) it could be done. > > overloadings: >     + ==> OR >     * ==> AND >     / ==> NOT > > Example original code: >      A=/B+C*D > translates to: >     A=not B

overloading for ladder logic

2008-11-07 Thread jimzat
I am trying to simulate the execution of some PLC ladder logic in python. I manually modified the rungs and executed this within python as a proof of concept, but I'd like to be able to skip the modification step. My thought was that this might be able to be completed via overloading, but

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...e

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 dep

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 dep

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

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 dep

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

Re: No method overloading

2008-08-24 Thread alex23
On Aug 24, 6:15 pm, Hussein B <[EMAIL PROTECTED]> wrote: > Please correct me if I'm wrong but Python doesn't support method > overload, right? Guido once wrote an article on rolling your own: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 -- http://mail.python.org/mailman/listinfo/pyth

Re: No method overloading

2008-08-24 Thread Fredrik Lundh
Hussein B wrote: Please correct me if I'm wrong but Python doesn't support method overload, right? -- def method(self): #code def method(self, data): #code -- The last declaration of method() erase the previous one (like JavaScript). in Python, methods are callable attributes, and an attribu

Re: No method overloading

2008-08-24 Thread MeTheGameMakingGuy
On Aug 24, 6:15 pm, Hussein B <[EMAIL PROTECTED]> wrote: > Hey, > Please correct me if I'm wrong but Python doesn't support method > overload, right? > -- > def method(self): >  #code > def method(self, data): >  #code > -- > The last declaration of method() erase the previous one (like > JavaScrip

No method overloading

2008-08-24 Thread Hussein B
Hey, Please correct me if I'm wrong but Python doesn't support method overload, right? -- def method(self): #code def method(self, data): #code -- The last declaration of method() erase the previous one (like JavaScript). Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading virtual method of widget without inheriting (PyQt)

2008-05-28 Thread Alex Gusarov
> I have a feeling that the form produced by Qt Designer, once converted to > code, contains references to QCalendarWidget where you really want to use a > customized calendar widget. If so, you should "promote" the calendar widget > in Qt Designer to use your widget instead, and make sure you impo

Re: Overloading virtual method of widget without inheriting (PyQt)

2008-05-27 Thread Francesco Bochicchio
> } > > I can't find how I can do similar thing in Python without inheriting > QCalendarWidget and overloading this method in inherited class (it's > long and I must create additional class). The only thing I done its > full replacement of handler: > > calendar.pai

Re: Overloading __getitem__

2008-05-24 Thread Gabriel Genellina
En Thu, 22 May 2008 20:38:39 -0300, Andreas Matthias <[EMAIL PROTECTED]> escribió: > [EMAIL PROTECTED] wrote: > >> actually i ddin't think about the fact that you're overloading dict, which >> can already take multiple values in getitem > > Oh, I didn&#

Re: Overloading __getitem__

2008-05-22 Thread inhahe
> Apparently, args already is a tuple, so this should be: > > def __getitem__(self, args): > > Is this documented somewhere? I couldn't find it anywhere. > Don't know, I just assumed it would take multiple arguments because I knew I had seen the form d[1,2] before, which incidentally is equival

Re: Overloading __getitem__

2008-05-22 Thread Andreas Matthias
[EMAIL PROTECTED] wrote: > actually i ddin't think about the fact that you're overloading dict, which > can already take multiple values in getitem Oh, I didn't know that. I totally misinterpreted the error message. > so how about > > class crazy: pass &g

Re: Overloading __getitem__

2008-05-22 Thread inhahe
actually i ddin't think about the fact that you're overloading dict, which can already take multiple values in getitem so how about class crazy: pass and then in your dict class: def __getitem__(*args): if args[-1] is crazy: return self.get(args[:-1])*5 else: return sel

Re: Overloading __getitem__

2008-05-22 Thread inhahe
"inhahe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > crazy = True > print foo['a',crazy] > just to clarify, you could use it like: crazy = "I'm crazy" #this only has to be done once print foo['a'] #not crazy print foo['a',crazy] #crazy (this may be totally unPythonic

Re: Overloading __getitem__

2008-05-22 Thread inhahe
it seems like you can't do it exactly the way you're trying but you could do this def __getitem__(*args): if len(args) > 1 and args[1]: return self.get(args[0]) * 5 return self.get(args[0]) then you would use it like print foo['a'] print foo['a',True] or even print foo['a',"crazy"] if you

Overloading __getitem__

2008-05-22 Thread Andreas Matthias
The following code doesn't run but I hope you get what I am trying to do. class my_dict (dict): def __getitem__ (self, key, crazy = False): if crazy == True: return 5 * self.get(key) else: return self.get(key) foo = my_dict() foo['a'] = 123 print fo

Re: Newbie Question - Overloading ==

2008-04-04 Thread Lie
On Apr 1, 2:22 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >> Surely an A isn't equal to every other object which just happens to > >> have the same attributes 'a' and 'b'? > > > And why not ?-) > > >> I would have thoughts the tests want to be > >

Re: Newbie Question - Overloading ==

2008-04-01 Thread Bruno Desthuilliers
Duncan Booth a écrit : > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >>> Surely an A isn't equal to every other object which just happens to >>> have the same attributes 'a' and 'b'? >> And why not ?-) >> >>> I would have thoughts the tests want to be >>> something like: >>> >>> class A: >>>

Re: Newbie Question - Overloading ==

2008-04-01 Thread Duncan Booth
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> Surely an A isn't equal to every other object which just happens to >> have the same attributes 'a' and 'b'? > > And why not ?-) > >> I would have thoughts the tests want to be >> something like: >> >> class A: >> def __eq__(self,other): >>

Re: Question about overloading of binary operators

2008-03-31 Thread Dan Bishop
On Mar 31, 5:03 pm, gigs <[EMAIL PROTECTED]> wrote: > Raj Bandyopadhyay wrote: > > Hi > > > Here's a simple class example I've defined > > > # > > class myInt(int): > >def __add__(self,other): > > return 0 > > > print 5 + myInt(4) #prints 9 > > print myInt(4)

Re: Question about overloading of binary operators

2008-03-31 Thread gigs
Raj Bandyopadhyay wrote: > Hi > > Here's a simple class example I've defined > > # > class myInt(int): >def __add__(self,other): > return 0 > > print 5 + myInt(4) #prints 9 > print myInt(4) + 5 #prints 0 > # > > The Python bi

Question about overloading of binary operators

2008-03-31 Thread Raj Bandyopadhyay
Hi Here's a simple class example I've defined # class myInt(int): def __add__(self,other): return 0 print 5 + myInt(4) #prints 9 print myInt(4) + 5 #prints 0 # The Python binary operation function (binary_op1() in Objects/a

Re: Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
On Mar 31, 3:42 pm, Amit Gupta <[EMAIL PROTECTED]> wrote: > On Mar 31, 11:00 am, xkenneth <[EMAIL PROTECTED]> wrote: > > > Yeah, this is what I'm talking about: > > > > def __eq__(self, other) : > > >   try : > > >      return <> > > >   except AttributeError: > > >      return False > > > That see

Re: Newbie Question - Overloading ==

2008-03-31 Thread Amit Gupta
On Mar 31, 11:00 am, xkenneth <[EMAIL PROTECTED]> wrote: > Yeah, this is what I'm talking about: > > > def __eq__(self, other) : > > try : > > return <> > > except AttributeError: > > return False > > That seems a bit nasty to me. One thing about python (IMO); you can't just say this

Re: Newbie Question - Overloading ==

2008-03-31 Thread [EMAIL PROTECTED]
On 31 mar, 20:09, Duncan Booth <[EMAIL PROTECTED]> wrote: > xkenneth <[EMAIL PROTECTED]> wrote: > > Now obviously, if I test an instance of either class equal to each > > other, an attribute error will be thrown, how do I handle this? I > > could rewrite every __eq__ function and catch attribute er

Re: Newbie Question - Overloading ==

2008-03-31 Thread Carl Banks
On Mar 31, 1:23 pm, xkenneth <[EMAIL PROTECTED]> wrote: > So i generally write quite a few classes, and in most I need to > overload the == operator. > > If i have two classes, like below: > > Class A: > attribute a > attribute b > > Class B: > attribute a > attribute c > > So if I've overloaded th

Re: Newbie Question - Overloading ==

2008-03-31 Thread Duncan Booth
xkenneth <[EMAIL PROTECTED]> wrote: > Now obviously, if I test an instance of either class equal to each > other, an attribute error will be thrown, how do I handle this? I > could rewrite every __eq__ function and catch attribute errors, but > that's tedious, and seemingly unpythonic. Also, I don

Re: Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
Yeah, this is what I'm talking about: > def __eq__(self, other) : >   try : >      return <> >   except AttributeError: >      return False That seems a bit nasty to me. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Question - Overloading ==

2008-03-31 Thread Jean-Paul Calderone
On Mon, 31 Mar 2008 10:23:24 -0700 (PDT), xkenneth <[EMAIL PROTECTED]> wrote: >So i generally write quite a few classes, and in most I need to >overload the == operator. > >If i have two classes, like below: > >Class A: >attribute a >attribute b > >Class B: >attribute a >attribute c > >So if I've o

Re: Newbie Question - Overloading ==

2008-03-31 Thread Amit Gupta
On Mar 31, 10:23 am, xkenneth <[EMAIL PROTECTED]> wrote: > > class A: > def __eq__(self,other): > return self.a == other.a and self.b == other.b > > class B: > def __eq__(self,other): > return self.a == other.a and self.c == other.c > > Thanks! > > Regards, > Kenneth Mille

Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
So i generally write quite a few classes, and in most I need to overload the == operator. If i have two classes, like below: Class A: attribute a attribute b Class B: attribute a attribute c So if I've overloaded their respective __eq__ functions, and I want to test whether or not the individua

Re: Function Overloading and Python

2008-03-02 Thread castironpi
On Feb 25, 11:04 am, [EMAIL PROTECTED] wrote: > > B1.fun(A(x), A(y), A(z)) == B.fun(A(x), A(y), A(z)) > > but > > B1.fun(A1(x), A(y), A(z) != B.fun(A1(x), A(y), A(z)) > > > Is there a data-structure solution or third party module that would > > mimic this behavior? > > class B: >    xfun= Overloade

Re: Function Overloading and Python

2008-02-25 Thread castironpi
> B1.fun(A(x), A(y), A(z)) == B.fun(A(x), A(y), A(z)) > but > B1.fun(A1(x), A(y), A(z) != B.fun(A1(x), A(y), A(z)) > > Is there a data-structure solution or third party module that would > mimic this behavior? ''' An Overloaded instance, B.xfun, is created in the base class of the classes the memb

Re: Function Overloading and Python

2008-02-25 Thread castironpi
On Feb 25, 1:33 am, Allen Peloquin <[EMAIL PROTECTED]> wrote: > I have a personal project that has an elegant solution that requires > both true multiple inheritance of classes (which pretty much limits my > language choices to C++ and Python) and type-based function > overloadi

Re: Function Overloading and Python

2008-02-25 Thread Carl Banks
On Feb 25, 2:33 am, Allen Peloquin <[EMAIL PROTECTED]> wrote: > I have a personal project that has an elegant solution that requires > both true multiple inheritance of classes (which pretty much limits my > language choices to C++ and Python) and type-based function > overloadi

Re: Function Overloading and Python

2008-02-25 Thread Gerald Klix
Stefan Behnel schrieb: > Allen Peloquin wrote: >> On Feb 24, 11:44 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote: >>> Allen Peloquin wrote: class B { fun(A x, A y, A z)... fun(A1 x, A y, A z)... } class B1 { fun(A1 x, A y, A z)... } Such t

Re: Function Overloading and Python

2008-02-25 Thread Bruno Desthuilliers
Allen Peloquin a écrit : > I have a personal project that has an elegant solution that requires > both true multiple inheritance of classes (which pretty much limits my > language choices to C++ and Python) and type-based function > overloading. > > Now, while this makes it so

Re: Function Overloading and Python

2008-02-25 Thread Stefan Behnel
Allen Peloquin wrote: > On Feb 24, 11:44 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote: >> Allen Peloquin wrote: >>> class B >>> { >>> fun(A x, A y, A z)... >>> fun(A1 x, A y, A z)... >>> } >>> class B1 >>> { >>> fun(A1 x, A y, A z)... >>> } >>> Such that any previous behavior is inherite

Re: Function Overloading and Python

2008-02-24 Thread Paul Rudin
Allen Peloquin <[EMAIL PROTECTED]> writes: > I have a personal project that has an elegant solution that requires > both true multiple inheritance of classes (which pretty much limits my > language choices to C++ and Python) and type-based function > overloading. > Com

Re: Function Overloading and Python

2008-02-24 Thread Allen Peloquin
(x,y,z) > # ... > > def _fun(x,y,z): > # ... > > class B1(B): > def _fun(x,y,z): > # ... > > Stefan The problem is that I want to reuse the code of the parent classes through inheritance, otherwise this would work fine. I am aware that because

Re: Function Overloading and Python

2008-02-24 Thread Stefan Behnel
Stefan Behnel wrote: > Allen Peloquin wrote: >> class B >> { >> fun(A x, A y, A z)... >> fun(A1 x, A y, A z)... >> } >> >> class B1 >> { >> fun(A1 x, A y, A z)... >> } >> >> Such that any previous behavior is inherited, but behaves >> polymorphically because of the single function name.

Re: Function Overloading and Python

2008-02-24 Thread Stefan Behnel
Allen Peloquin wrote: > class B > { > fun(A x, A y, A z)... > fun(A1 x, A y, A z)... > } > > class B1 > { > fun(A1 x, A y, A z)... > } > > Such that any previous behavior is inherited, but behaves > polymorphically because of the single function name. Try something like this: class

Function Overloading and Python

2008-02-24 Thread Allen Peloquin
I have a personal project that has an elegant solution that requires both true multiple inheritance of classes (which pretty much limits my language choices to C++ and Python) and type-based function overloading. Now, while this makes it sound like I have to resign myself to C++, which I am not a

Re: Operator overloading

2008-01-26 Thread Terry Reedy
| > > Sure. Cosines are a monadic operation and the monadic '+' is a NOP, so | > > why shouldn't I define +45 to return cosine of 45, (presuming I needed | > > lots of cosines). I'd even let you define your own operators. Lots of | > > programmers really liked '++' and '--', for examples. One c

Re: Operator overloading

2008-01-26 Thread MRAB
On Jan 25, 8:52 pm, Hexamorph <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > Hexamorph wrote: > >> You mean you want the ability to change for example the + operator > >> for ints to something like calculating the cosine instead of doing > >> addition? > > > Sure. Cosines are a monadic

Re: Operator overloading

2008-01-25 Thread Hexamorph
[EMAIL PROTECTED] wrote: > > Hexamorph wrote: >> You mean you want the ability to change for example the + operator >> for ints to something like calculating the cosine instead of doing >> addition? > > Sure. Cosines are a monadic operation and the monadic '+' is a NOP, so > why shouldn't I defin

Re: Operator overloading

2008-01-25 Thread MartinRinehart
Hexamorph wrote: > You mean you want the ability to change for example the + operator > for ints to something like calculating the cosine instead of doing > addition? Sure. Cosines are a monadic operation and the monadic '+' is a NOP, so why shouldn't I define +45 to return cosine of 45, (presum

Re: Operator overloading

2008-01-25 Thread Hexamorph
[EMAIL PROTECTED] wrote: > > Diez B. Roggisch wrote: >> No, there is no way. You would change general interpreter behavior if >> you could set arbitrary operators for predefined types. >> >> Start grumping... > > Thank you, Diez. > > If I ever design a language, please remind me that complete, e

Re: Operator overloading

2008-01-25 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > > Diez B. Roggisch wrote: >> No, there is no way. You would change general interpreter behavior if >> you could set arbitrary operators for predefined types. >> >> Start grumping... > > Thank you, Diez. > > If I ever design a language, please remind me that complete,

Re: Operator overloading

2008-01-25 Thread MartinRinehart
Diez B. Roggisch wrote: > No, there is no way. You would change general interpreter behavior if > you could set arbitrary operators for predefined types. > > Start grumping... Thank you, Diez. If I ever design a language, please remind me that complete, easy, well-documented access to the worki

Re: Operator overloading

2008-01-25 Thread Diez B. Roggisch
so it works my way but operator overloading > seems strictly confined to classes I create. Is there a way? Or do I > just have to grump, "Even a kludge like Perl ..."? > No, there is no way. You would change general interpreter behavior if you could set arbitrary operators for

Operator overloading

2008-01-25 Thread MartinRinehart
If it were my choice, the plus sign would do this: def itemadd( i1, i2 ): if ( type(i1) == str ) or ( type(i2) == str ): return str(i1) + str(i2) else: return i1 + i2 I'd like to redefine it so it works my way but operator overloading seems strictly confined to clas

Re: operator overloading on built-ins

2007-11-08 Thread Marc 'BlackJack' Rintsch
On Thu, 08 Nov 2007 22:53:16 -0800, r.grimm wrote: (1).__cmp__(10) > -1 As the dot is an operator like ``+`` or ``/`` you can also add spaces to avoid the ambiguity: In [493]: 1 . __cmp__(10) Out[493]: -1 In [494]: 1 .__cmp__(10) Out[494]: -1 Ciao, Marc 'BlackJack' Rintsch -- htt

Re: operator overloading on built-ins

2007-11-08 Thread Steven Bethard
[EMAIL PROTECTED] wrote: (1).__cmp__(10) > -1 Integer object "(1)" followed by method call ".__cmp__(10)" 1.__cmp__(10) > File "", line 1 > 1.__cmp__(10) > ^ > SyntaxError: invalid syntax Floating point number "1." followed by "__cmp__(10)". STeVe -- http://mail.pyt

  1   2   3   4   >