Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. My code is working but give me some error, "name 'self' is not defined"
Forum Updated to NodeBB v4.3 + New Features

My code is working but give me some error, "name 'self' is not defined"

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 132 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coutKateM
    wrote on last edited by
    #1

    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
        
    
    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      In you main function, self is absolutely meaningless. Please read some basic info about Python methods: the self keyword is the equivalent of the this pointer in C++, it should not be provided as argument explicitly.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved