The code below implements a class that works with the sum() function but only if wrapped in a list first. Without [] Python will complain that it's a non-sequence. What needs to be done so I don't have to wrap it in a list? I'm guessing I need to implement __iter__ but I don't know what it should look like.

sum() accepts as an argument an iterable object. Your class (a vector?) doesn't look like it is an object which should be iterable. More likely, you should have a well-named method that does the operation you want. I'm not sure what adding the components of a vector is supposed to be for.

Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.

The result might not be correct (yet) as the code isn't working yet. But you are probably right that I should just define a method for this.

But apart from that, I also see examples (for making a class an iterable) that implement __iter__(), next() and something with StopIteration (can't find the link anymore :/ ). Assuming there's a legitemate case for making a class iterable, would this (__iter__(), next() and something with StopIteration) be better than using yield?

Edit: Hmm, it's a bit of a mess as I'm editing the code atm. The first code block is obviously missing the sample.x, sample.y and sample.z that should be there.