Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Python error saying "AttributeError: can't set attribute"

Asked by Ranjana Admin Apr 15, 2021 1.5K views 1 answer
Share

About this question

 I'm trying to execute the following python code:
class C(object):
    def __init__(self):
        self._x = 0
    @property
    def x(self):
        print 'getting'
        return self._x
    @x.setter
    def set_x(self, value):
        print 'setting'
        self._x = value
if __name__ == '__main__':
    c = C()
    print c.x
    c.x = 10
    print c.x
But I get the following attributeerror: can't set attribute:
pydev debugger: starting
getting
0
File "test.py", line 55, in 
c.x = 10
AttributeError: can't set attribute

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.