Error: "TypeError: list indices must be integers, not str" in Python -
i trying import data file , using in function getting error:
door_position_pattern_actual = door_position[d]
typeerror: list indices must integers, not str
code references:
reactive_sampling_period_in_seconds = 10 * 60 door_position = list() while 1: line = f.readline() vals = f.readline() vals= vals.rstrip() data1 = [] v in vals.split(","): data1.append(v.lstrip()) if(entry[1]=="doorposition"): door_position = list(data1) def door_positin_fnc_actual(self, time_in_seconds): time_period_in_10mins = 6 index = int(math.floor(time_in_seconds%(144*reactive_sampling_period_in_seconds)/(reactive_sampling_period_in_seconds))) d in door_position : door_position_pattern_actual = door_position[d] return door_position_pattern_actual[index]
output references:
print(door_position) ['(1', '1', '1', '0', '1', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '0', '1', '1', '1)']
i suspecting (1 creating prob not able fix it, kindly suggest me ...!!!
this wrong:
for d in door_position : door_position_pattern_actual = door_position[d]
d
not index, it's value. doesn't make sense use in door_position[ ... ]
the error typeerror: list indices must integers, not str
comes here.
perhaps looking this:
for d in range(len(door_position)) : door_position_pattern_actual = door_position[d]
Comments
Post a Comment