-I don't like to ask this type of questions, however I'm a bit short on time and I'm quite curious to know why a code as simple as this doesn't work...
class Persona:
def __init__(self, nombre, apellido):
self.nombre = nombre
self.apellido = apellido
@property
def nombre_completo(self):
return self.nombre.capitalize() + ' ' + self.apellido.capitalize()
@nombre_completo.setter
def nombre_completo(self, nuevo_nombre):
nombre,apellido = nuevo_nombre.split(' ')
self.nombre = nombre
self.apellido = apellido
@nombre_completo.deleter
def nombre_completo(self):
del self.nombre
del self.apellido
persona_nueva = persona('Juan', 'Peres')
print(persona_nueva.nombre_completo)
persona.nombre_completo = 'Nelson Martinez'
print(persona_nueva.nombre_completo)
del persona_nueva.nombre_completo
-Returns (at least on my machine with windows 10 and python 3.9.5) AttributeError
, it is due to a problem in deleter
which I cannot identify...
In the code
property.deleter
it is seen that it works normally,AttributeError
it happens to you because you are calling the propertynombre_completo
from the class itselfPersona
(in this casepersona
it would be but I assumed it was an error when copying the code), simply change itPersona
topersona_nueva
and it will give you the desired result :Result: