Problems with classes and __add__ and __mul__...

abg at saturnsys.com abg at saturnsys.com
Thu Jun 15 18:52:31 EDT 2000


Hi all,
   I'm having a little problem with classes right now.  It's a class
with a list as it 's main feature.  I've done the slices and such so that
instance[:] and instance[x] work.  However, I can't seem to get
__add__ and __mul__ to function the way that I want them to.

I would like to do this...
def __add__(self, other_instance):
    return self.list + other_instance.list

Which returns a list.  I would like to return an object of my class type, but
it's not right obvious to me as to how to do that.

Or, would it be better to do this?  (spam is the class here...)
x = spam()
y = spam()
z = spam()
z[:] = x + y

or should I just define an append function for the class?

(What I really want to do is this:
z = spam()
x = spam()
z = z+x

Thanks for any help that you can give me.  It would be great if you emailed
your responses to a_gurno at yahoo.com as I don't always get to check this group
as often as I would like. Adam


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list