[Tutor] operator overloading considered harmful ;-)

2009-11-07 Thread spir
Hello, I jump on the opportunity offered by the previous thread to tell a little story (serious only people disgard). Guess this is a candidate for Bug of the Year. I was filtering (parse) results to keep only nodes from a given set of types: for child in node: if child.pattern in item_type

Re: [Tutor] Operator Overloading

2005-04-04 Thread Kevin Reeder
On Tue, 05 Apr 2005 10:56:40 +1200 (NZST) [EMAIL PROTECTED] wrote: > Fine, but always test the simplified version, unless you're > absolutely certain what you're throwing out! Point taken. > When you do 'A + [4, 5, 6]', python first calls > A.__getattr__('__coerce__'). Everything's working fine

Re: [Tutor] Operator Overloading

2005-04-04 Thread jfouhy
Quoting Kevin Reeder <[EMAIL PROTECTED]>: > On Mon, 04 Apr 2005 21:14:21 +1200 > John Fouhy <[EMAIL PROTECTED]> wrote: > > Are you sure you've giving us all the code? > No, I was trying to keep it simple. Anyway, here it is, Fine, but always test the simplified version, unless you're absolutely c

Re: [Tutor] Operator Overloading

2005-04-04 Thread Kevin Reeder
On Mon, 04 Apr 2005 21:14:21 +1200 John Fouhy <[EMAIL PROTECTED]> wrote: > Are you sure you've giving us all the code? No, I was trying to keep it simple. Anyway, here it is, class MyList: def __init__(self, start): self.wrapped = [ ] for x in start: self.wrapped.append(x)

Re: [Tutor] Operator Overloading

2005-04-04 Thread John Fouhy
Kevin Reeder wrote: This is not my code but is taken from the book I'm working with. My problem is that whenever I call to the __add__ method the counters increase by 2 while calls the __len__ method increase the counters by 1 as expected. Well, I can't duplicate your results.. I get the behaviou

[Tutor] Operator Overloading

2005-04-03 Thread Kevin Reeder
Following an example from a book, I'm getting an unexpected outcome. The point of exercise is to extend operator overloading methods from a superclass and track the method calls. Here's the code, class MyList: def __init__(self, start): self.wrapped = [ ] for x in start: self.w