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

  • Home
  • SEARCH
  • 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 4608098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:47:47+00:00 2026-05-22T00:47:47+00:00

Say I define this descriptor: class MyDescriptor(object): def __get__(self, instance, owner): return self._value def

  • 0

Say I define this descriptor:

class MyDescriptor(object):

   def __get__(self, instance, owner):
        return self._value

    def __set__(self, instance, value):
        self._value = value

    def __delete__(self, instance):
        del(self._value)

And I use it in this:

class MyClass1(object):
    value = MyDescriptor()


>>> m1 = MyClass1()
>>> m1.value = 1
>>> m2 = MyClass1()
>>> m2.value = 2
>>> m1.value
2

So value is a class attribute and is shared by all instances.

Now if I define this:

class MyClass2(object)
    value = 1

>>> y1 = MyClass2()
>>> y1.value=1
>>> y2 = MyClass2()
>>> y2.value=2
>>> y1.value
1

In this case value is an instance attribute and is not shared by the instances.

Why is it that when value is a descriptor it can only be a class attribute, but when value is a simple integer it becomes an instance attribute?

  • 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-22T00:47:48+00:00Added an answer on May 22, 2026 at 12:47 am

    You’re ignoring the instance parameter in your implementation of MyDescriptor. That is why it appears to be a class attribute. Perhaps you want something like this:

    class MyDescriptor(object):
    
        def __get__(self, instance, owner):
            return instance._value
    
        def __set__(self, instance, value):
            instance._value = value
    
        def __delete__(self, instance):
            del(instance._value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class Code defined like this, with a user specified type
Say I have a structure like this: class AAA { BBB bb_member; double dbl_member;
Let's say I have something like this: <?php namespace Twitter; class Twitter { function
Say you have an object A with property B and you want to define
Let's say we have defined a CSS class that is being applied to various
Say I've got this array: MyArray(0)=aaa MyArray(1)=bbb MyArray(2)=aaa Is there a .net function which
Say I have a class named Frog, it looks like: public class Frog {
I have a class that contains a member object. I would like to call
Say I have a file Foo.php: <?php interface ICommand { function doSomething(); } class
Say I have: #define MY_MACRO(FOO) void FOO(); MY_MACRO(hi); MY_MACRO(hey); MY_MACRO(hello); #undef MY_MACRO I want

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.