Python error saying "AttributeError: can't set attribute". How is it possible?

15.1K    Asked by ChrisEVANS in Python , Asked on Feb 28, 2021
Answered by Chris EVANS

The explanation you are getting this error is that you are naming the setter method mistakenly. You have named the setter method as set_x which is off base, this is the reason you are getting the Attribute Error.

To fix this error, rather than naming it as set_x you need to give it a similar name as the property you making a setter for, for your situation, you can do it like this:

@x.setter

def x(self, value):

    'setting'

    self._x = value



Your Answer

Interviews

Parent Categories