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 101123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:42:38+00:00 2026-05-11T00:42:38+00:00

To illustrate the question check the following code: class MyDescriptor(object): def __get__(self, obj, type=None):

  • 0

To illustrate the question check the following code:

class MyDescriptor(object):   def __get__(self, obj, type=None):     print 'get', self, obj, type     return self._v   def __set__(self, obj, value):     self._v = value     print 'set', self, obj, value     return None  class SomeClass1(object):   m = MyDescriptor()  class SomeClass2(object):   def __init__(self):     self.m = MyDescriptor()  x1 = SomeClass1() x2 = SomeClass2()  x1.m = 1000 # ->  set <__main__.MyDescriptor object at 0xb787c7ec> <__main__.SomeClass1 object at 0xb787cc8c> 10000 x2.m = 1000 # I guess that this overwrites the function. But why? # -> print x1.m # -> get <__main__.MyDescriptor object at 0xb787c7ec> <__main__.SomeClass1 object at 0xb787cc8c> <class '__main__.SomeClass1'> 10000 print x2.m # -> 10000 
  1. Why doesn’t x2.m = 1000 not call the __set__-function? It seems that this overwrites the function. But why?
  2. Where is _v in x1? It is not in x1._v
  • 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. 2026-05-11T00:42:38+00:00Added an answer on May 11, 2026 at 12:42 am

    To answer your second question, where is _v?

    Your version of the descriptor keeps _v in the descriptor itself. Each instance of the descriptor (the class-level instance SomeClass1, and all of the object-level instances in objects of class SomeClass2 will have distinct values of _v.

    Look at this version. This version updates the object associated with the descriptor. This means the object (SomeClass1 or x2) will contain the attribute _v.

    class MyDescriptor(object):   def __get__(self, obj, type=None):     print 'get', self, obj, type     return obj._v   def __set__(self, obj, value):     obj._v = value     print 'set', self, obj, value 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will be using the following example to illustrate my question: class Attribute {}
To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck
I guess I'll illustrate with an example: In this game you are able to
Can someone illustrate what really is the difference between the two?
I'll be using the AdventureWorks Database to illustrate my problem. I need to show
Is it possible to implement autoboxing for your own classes? To illustrate my example,
I'm writing a password encryption routine. I've written the below app to illustrate my
I would like to execute multiple commands in a row: i.e. (just to illustrate
Here's a minimal batch file, demo.bat , to illustrate my problem: @ECHO off set
I'm not really writing an alarm clock application, but it will help to illustrate

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.