How to iterate over an instance object's data attributes, returning two values at a time?

Posted by Spikie on Stack Overflow See other posts from Stack Overflow or by Spikie
Published on 2010-04-13T12:55:41Z Indexed on 2010/04/13 13:03 UTC
Read the original article Hit count: 263

Filed under:
|

I need to return two values at a time, so I have:

class IterableObject(object):
  def __iter__(self):
    for item in self.__dict__:
      return  self.__dict__[item + 1], self.__dict__[item]

So I can have:

myObj1, myObj2 = IterableObject()

value = myObj1.balance - myObj2.balance

Of course it did not work. What am I doing wrong? I think I can not add value on item like that.

© Stack Overflow or respective owner

Related posts about python

Related posts about iterator