Method declared but not found in a class object

Question:

I just began the long and painful journey in Python Class Objects and try this:

class UgcObject:
       
    def __init__(self, strPlateformeOld, strIdOld):
        self.strPlateformeOld = strPlateformeOld
        self.strIdOld = strIdOld
     
    def GetApiUpdatedMetadata(self):    
        if self.strPlateforme == "youtube":        
           return True      
           
    def GetblnUpdatePossible(self):
        return GetApiUpdatedMetadata()
    
   

if __name__ == '__main__':
    ugc_test = UgcObject("youtube","id")
    print(ugc_test.GetblnUpdatePossible())

I got an error message: NameError: name 'GetApiUpdatedMetadata' is not defined
I don’t get why considering that I believe the GetApiUpdatedMetadata is declared and above the method that calls it.

What did I did wrong?

Asked By: 8oris

||

Answers:

If you are trying to call another method in the same class it should have self. in front of it, and the variable name self.strPlateforme is wrong:

class UgcObject:
       
    def __init__(self, strPlateformeOld, strIdOld):
        self.strPlateformeOld = strPlateformeOld
        self.strIdOld = strIdOld
     
    def GetApiUpdatedMetadata(self):    
        if self.strPlateformeOld == "youtube":        
            return True      
           
    def GetblnUpdatePossible(self):
        return self.GetApiUpdatedMetadata()
    
   

if __name__ == '__main__':
    ugc_test = UgcObject("youtube","id")
    print(ugc_test.GetblnUpdatePossible())
Answered By: NYC Coder
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.