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

0 votes

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 error:

pydev debugger: starting
getting
0
File "\test.py", line 55, in <module>
c.x = 10
AttributeError: can't set attribute
May 30 in Python by Kamal
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

change your code to the following:

@x.setter
def x(self, value):
    'setting'
    self._x = value
answered May 30 by Imran

Related Questions In Python

0 votes
1 answer

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

There is no attribute called “rows”. The ...READ MORE

answered Mar 28 in Python by Shri
634 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,500 points
451 views
0 votes
1 answer

python nmap can't find PortScanner attribute

As I can see in the error ...READ MORE

answered Jan 30 in Python by Omkar
• 66,910 points
229 views
0 votes
1 answer

what is attribute error in python?

import pandas df = pd.read_csv('filename') it will give attribute ...READ MORE

answered Mar 27 in Python by Mohammad
• 1,400 points
71 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 views
+4 votes
6 answers
0 votes
1 answer

Python error "AttributeError: '_Screen' object has no attribute 'mainloop'" python module turtle

Hey @Nagya, replace  wn.mainlopp() with turtle.mainloop() a ...READ MORE

answered 14 hours ago in Python by Faiza
8 views
0 votes
1 answer

Python error "AttributeError: 'Turtle' object has no attribute 'Shape'"

Hey @Nagya, replace python.Shape("Square") with the following: python.shape("square") Python is case ...READ MORE

answered 14 hours ago in Python by Faiza
3 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.