I have some class
:
import numpy as np
class SomeClass:
def __init__(self):
self.x = np.array([1,2,3,4])
self.y = np.array([1,4,9,16])
is there a neat way to iterate over x
and y
for some instance of SomeClass
in Python? Currently to iterate over the variables I would use:
some_class = SomeClass()
for x, y in zip(some_class.x, some_class.y):
print(x, y)
... but can you define SomeClass
's behaviour such that the same would work:
some_class = SomeClass()
for x, y in some_class:
print(x, y)
Thanks for any help!