Code snippet:
data = [("a", "b", "c", "d"),("e", "f", "g", "h")]
for i in data:
console = '{}_{}'.join(('consoleip',str(i[2])))
<> = Hostdata(hw_id = i[0],location_id = i[1],consoleip = i[2], biosversion = i[3])
Expected result:
consolip_c = Hostdata(hw_id ='a', location_id ='b', consoleip ='c', biosversion ='d')
consolip_g = Hostdata(hw_id ='e', location_id ='f', consoleip ='g', biosversion ='h')
Im looping through the data, which holds thousands of database records and I want each record to be held in a distinct variable unique to the record. This would help me access each record with a unique named tuple variable.
How can I fill in the gap for <>
, to assign a the namedtuple(Hostdata)
to the value associated for console. Because I get a "SyntaxError: can't assign to function call" when I directly use:
'{}_{}'.join(('consoleip',str(i[2]))) = Hostdata(hw_id = i[0],location_id = i[1],consoleip = i[2],biosversion = i[3])