My code is working but give me some error, "name 'self' is not defined"
-
Hope that's someone will now this self. & init problem solution.
My code working without INIT ans Self. But I need to add it for future use, Thank you in advance!class PlateString: def __init__(self, threshold=0.05): self.threshold = threshold max_list_from_all_plates = [] #self.threshold = threshold for single_lp in seq: maximum_plate_prob = [] possible_plate_prob = [] max_list = [] plateresults = [] for sign in single_lp: high_indexes = [] for prob_id in range(0,len(sign)): if self.threshold<sign[prob_id]: high_indexes.append([sign[prob_id], prob_id, CATEGORIES[prob_id]]) max_list.append(high_indexes) max_list_from_all_plates.append(max_list) listaMain = [] ListaVal = [] self.checklen(max_list_from_all_plates, listaMain, ListaVal, plateresults) def checklen(self, max_list_from_all_plates, listaMain, ListaVal, plateresults): for plate in max_list_from_all_plates: maxlen = 0 if len(plate) > maxlen: maxlen = len(plate) print(maxlen) textPlate : str= "" sumplate = 0 for probabilities in plate: znakMax : str = "" probabilityMax : float = 0 for probability in probabilities: if(probabilityMax<probability[0]): probabilityMax = probability[0] znakMax = probability[2] valMax = probability[0] textPlate += znakMax sumplate += valMax listaMain.append(textPlate) ListaVal.append(sumplate) for i in range(len(listaMain)): info = [ListaVal[i], listaMain[i]] plateresults.append(info) print(plateresults) if __name__ == '__main__': PlateString(threshold=0.05).checklen(self, max_list_from_all_plates, listaMain, ListaVal, plateresults)#ERRROR IS HERE name 'self' is not defined
-
In you
main
function,self
is absolutely meaningless. Please read some basic info about Python methods: theself
keyword is the equivalent of thethis
pointer in C++, it should not be provided as argument explicitly.