I have a class Test that has attributes Test.att1, Test.att2, ... , Test.att10. I have a method Test.update() that computes ten new values vals = [v1, v2, ... , v10]. I'd like to update Test's attributes in a single for loop.
I envision something like looping through the list mylist = [self.att1, self.att2, ... , self.att10] within the Test class and setting values per vals but this didn't seem to work. What can I do instead / what's the best way to update multiple attributes without using a self.att1, self.att2, self.att3 = v1, v2, v3 structure?
EDIT: I'm specifically asking because I am doing something like:
a1, a2, a3, a4, a5 = self.update()
self.a1 = pd.concat([self.a1, a1]).drop_duplicates().reset_index(drop=True)
self.a2 = pd.concat([self.a2, a2]).drop_duplicates().reset_index(drop=True)
self.a3 = pd.concat([self.a3, a3]).drop_duplicates().reset_index(drop=True)
self.a4 = pd.concat([self.a4, a4]).drop_duplicates().reset_index(drop=True)
self.a5 = pd.concat([self.a5, a5]).drop_duplicates().reset_index(drop=True)
and am currently using One backwards way I ended up doing this was:
def update(self):
dfs = [self.att1, self.att2, ..., self.att10]
dfs = [pd.concat([dfs[i], vals[i]]).drop_duplicates().reset_index(drop=True) \
for i in range(len(dfs))]
[self.att1, self.att2, ..., self.att10] = dfs
but at seeking a better way
pd.concat([self.att1,df]).drop_duplicates().reset_index(drop=True)so I was wondering how to only write once and avoid writing 10 times...