I'm creating a class with this method that computes for the centroid of a given area from coordinates. This is my code so far. And I'm having this error in jupyter notebook : NameError: name '_Lot__getCentroid' is not defined. What am I doing wrong? I'm trying to just follow this UML given to me. Should I move the method getCentroid first before the initialization? I'm not sure that's customary with classes but I'm new to it so I don't know.
There two reasons why your code will not work:
self.centroid = __getCentroid()
will work only if __getCentroid()
function will be declared outside the class. If it's inside the class, you should call self.__getCentroid()
__getCentroid()
is a static method and has no access to class or instance attributes. So you don't have access to self.*something*
. If you use IDE such a Pycharm, it will show you the error.Just read a little bit more about classes, their attributes and methods in python :)