How to iterate over an instance object's data attributes, returning two values at a time?
- by Spikie
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.