Home > Back-end >  TypeError: 'NoneType' object is not callable - python
TypeError: 'NoneType' object is not callable - python

Time:02-14

I have been reading about this error and I understand that it is because I expect a function to return a result but in reality it is not, I have reviewed my code and I do not find that it could be wrong

class Estudiante:
   def __init__(self):
      self.nombre = ""
      self.cedula = 0
      self.apellido = ""
      self.asignatura = ""
      self.cantidadDeNotas = 0
      self.notas = []

   @property
      def obtenerDatos(self):
         print("ingrese los datos del estudiante")
         self.cedula = int(input("Cedula del estudiante: "))
         self.nombre = input("Nombre del estudiante: ")
         self.apellido = input("Apellido del estudiante: ")
         self.asignatura = input("Asignatura: ")
         while True:
            self.cantidadDeNotas = int(input("¿cual es la cantidad de notas que desea ingresar?(más de 4): "))
            if self.cantidadDeNotas > 4:
                break
            else:
                print("ingrese una cantidad mayor a 4")
    
estudiante = Estudiante()
estudiante.obtenerDatos()

CodePudding user response:

When you decorate a method as @property, it will automatically become a getter method for a property it is named after. It is then accessed not as object.method() but object.method (which will still call the same method underneath, and evaluate to its return value).

In your case, you are declaring obtenerDatos a property getter, but then calling estudiante.obtenerDatos(). This would be like calling estudiante.obtenerDatos()() if there were no @property tag - you call the method and then try to call its return value as a function.

Since the method does not return a value, this means your code tries to call None as a function.

  • Related