class spreadsheetrow(object): def __init__(self,account1): self.account1=account1 self.account2=0
i have while loop fills list of objects (called listofspreadsheetrowobjects) ,and loop fills dictionary associating var1:account2 (called dict_var1_to_account_2). but, need dictionary's value each object, if key matches object's account1.
so basically, have:
listofspreadsheetrowobjects=[spreadsheetrow1, spreadsheetrow2, spreadsheetrow3] dict_var1_to_account2={1234:888, 1991:646, 90802:5443}
i've tried this:
for k, v in dict_var1_to_account2.iteritems(): if k in listofspreadsheetrowobjects: if account1=k: account2=v
but, it's not working, , suspect it's first "if" statement, because listofspreadsheetrowobjects list of objects, don't think it's talking attributes of objects in list. but, i've tried if any(k == item.account1 item in listofspreadsheetrows): , , doesn't seem pull @ either.
how access account1 of each object, can match them needed?
eventually, should have 3 objects following information:
spreadsheetrow self.account1=account1 self.account2=(v dictionary, if account1 matches key in dictionary)
it looks easier iterate on row objects first, , each 1 check if account1
in dict:
for row in listofspreadsheetrowobjects: if row.account1 in dict_var1_to_account2: row.account2 = dict_var1_to_account2[row.account1]
Comments
Post a Comment