Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Method declared but not found in a class object

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 NameError: name ‘GetApiUpdatedMetadata’ is not defined and i don’t get why considering the GetApiUpdatedMetadata is declared and above the method that calls it.

What did i did wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading