Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1093967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:54:16+00:00 2026-05-16T23:54:16+00:00

Based on a question I previously asked , I tried to come up with

  • 0

Based on a question I previously asked, I tried to come up with a class property that would allow setting as well as getting. So I wrote this and put it in a module util:

class classprop(object):
    def __init__(self, fget, fset=None):
        if isinstance(fget, classmethod):
            self.fget = fget
        else:
            self.fget = classmethod(fget)
        if not fset or isinstance(fset, classmethod):
            self.fset = fset
        else:
            self.fset = classmethod(fset)
    def __get__(self, *a):
        return self.fget.__get__(*a)()
    def __set__(self, cls, value):
        print 'In __set__'
        if not self.fset:
            raise AttributeError, "can't set attribute"
        fset = self.fset.__get__(cls)
        fset(value)

class X(object):
    @classmethod
    def _get_x(cls):
        return 1
    @classmethod
    def _set_x(cls, value):
        print 'You set x to {0}'.format(value)
    x = classprop(fget=_get_x, fset=_set_x)

While getting is working, setting doesn’t seem to be getting called:

>>> util.X.x
1
>>> util.X.x = 1
>>> 

What am I doing wrong?

(And I have seen implementations of this that work a bit differently. I’m specifically wanting to know why this implementation isn’t working.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:54:17+00:00Added an answer on May 16, 2026 at 11:54 pm

    The doc’s say:

    object.__set__(self, instance,
    value)
    Called to set the attribute on
    an instance instance of the owner
    class to a new value, value.

    Unlike for __get__, it does not mention class attributes. So Python won’t call any __set__ on a class attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is based on this previously asked question : Magento custom module date
I asked a similar question previously, but it was so vague that I couldn't
Based on my previous question here and here , I found that I can
Sorry for this based question. I am fresh to jqplot and would like to
Previously I asked this question: Read quicktime movie from servlet in a webpage? Basically
based my previous question asked here: Jquery Filter List DIVs via checkboxes i got
Based off of a previous question I asked, which @Andrie answered, I have a
Based on a previous question, where I asked about IDEs to support development in
I'd previously asked a similar question, however it was slightly ambiguous and didn't generate
I'v asked these question some time ago: Multiple inheritance casting from base class to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.