Is there a difference between an object created inside of a program and one created from the IDLE prompt? I created a Reset(ShapeSet) which will just repopulate its parameter with a few shapes for testing. But if I create a shape at the prompt and add it to the set, type(sh) != type(setMember) when it should.
http://codepad.org/LLNrJgpL This is the code for the reset and the addShape. addShape checks against type so that the list is sorted for display. However, for some reason, if you run Reset(ss1) and then square = Square(x), ss1.addShape(square), it will append the square, rather than placing it in the right position. When you check type(square)==type(ss1.members[x]), it will return false. I can't understand how this is even possible.
Further confusion: if you print out the types in the set, this is what you get: <class '__main__.Triangle'> (from Reset) <class '__main__.Triangle'> (from Reset) <class '__main__.Circle'> (from Reset) <class '__main__.Square'> (from Reset) <class '__main__.Triangle'> (added manually from the prompt) <class '__main__.Square'> (added manually from the prompt) <class '__main__.Square'> (added manually from the prompt)
Hmm, I suspect that it might have to do with deep comparison versus shallow comparison. I will try to fiddle around with the code. Another thing: "if sh.area > self.members[i]:", do you mean sh.area > self.members[i].area? Or am I missing something here? sh is an object to be added to the self that called the method, right?
bmp: I do mean self.member[i].area(), which was causing another bug which I didn't notice until later, but has been fixed. Side question: my understanding is that I need the parens for members[i].area() because it's a method, but I'm not sure that's right. Just an idle curiosity if you happen to know the answer.
Yeah, my bad. The parens are necessary. If they are ommited, you are refering to the method bound to the object instance member[i] , if I recall correctly.
Join our real-time social learning platform and learn together with your friends!