I have a class like this...
class person:
def __init__(self, name):
self.name = name
self.carData = ""
self.HouseData = ""
#other assets
And I'm looping through it like this...
john = person('John');
for index, row in john.carData.iterrows():
#do something
for index, row in john.HouseData.iterrows():
#do something
But in this case "do something" is repetitive code - I want to do the same thing for carData, HouseData and all the other assets a person can own.
What's the best way to loop through these in a non-repetitive way? I was thinking of something like this in the class definition but I'm pretty sure it's at least inelegant and probably wrong...
class person:
def __init__(self, name):
self.name = name
self.carData = ""
self.HouseData = ""
#other assets
self.assets = [self.carData, self.HouseData etc]
john = person('John');
for asset in john.assets:
for index, row in asset.iterrows():
#do something
Is that bad practise to define a list of objects (in this case self.assets) that itself refers to the same objects stored in the class? Apologies if this is vague - I'm just trying to figure out the cleanest way to deal with this scenario.