I have an error when creating my instance
#! python3
class Profile(object):
"""contiene la informacion del perfil"""
def __init__(self):
self.name = None
@property
def name(self):
"""name"""
return self.name
if __name__ == '__main__':
profile1 = Profile()
The error that throws me:
Traceback (most recent call last):
File "F:\Project\profile.py", line 14, in <module>
profile1 = Profile()
File "F:\Project\profile.py", line 6, in __init__
self.name = None
AttributeError: can't set attribute
I've been turning it around for a while, but I don't see any sense in it
The problem is caused because your attribute
self.name
is colliding with the propertyname
, and by doing so it wants to use the property's setter. The common thing is to set the name of the attribute with:_
, for example in your case it changesself.name
withself._name
.Or implement the setter: