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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:08:25+00:00 2026-06-02T21:08:25+00:00

class Books(): def __init__(self): self.__dict__[‘referTable’] = 1 @property def referTable(self): return 2 book =

  • 0
class Books():
    def __init__(self):
        self.__dict__['referTable'] = 1

    @property
    def referTable(self):
        return 2

book = Books()
print(book.referTable)
print(book.__dict__['referTable'])

Running:

vic@ubuntu:~/Desktop$ python3 test.py 
2
1

Books.referTable being a data descriptor is not shadowed by book.__dict__['referTable']:

The property() function is implemented as a data descriptor.
Accordingly, instances cannot override the behavior of a property.

To shadow it, instead of property built-in descriptor i must use my own descriptor. Is there a built in descriptor like property but which is non-data?

  • 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-06-02T21:08:27+00:00Added an answer on June 2, 2026 at 9:08 pm

    To expand on my comment, why not simply something like this:

    >>> class Books():
    ...     def __init__(self):
    ...         self.__dict__['referTable'] = 1
    ...     @property
    ...     def referTable(self):
    ...         try:
    ...             return self.__dict__['referTable']
    ...         except KeyError:
    ...             return 2
    ... 
    >>> a = Books()
    >>> a.referTable
    1
    >>> del a.__dict__['referTable']
    >>> a.referTable
    2
    

    Now, I’d like to note that I don’t think this is good design, and you’d be much better off using a private variable rather than accessing __dict__ directly. E.g:

    class Books():
        def __init__(self):
            self._referTable = 1
    
        @property
        def referTable(self):
            return self._referTable if self._referTable else 2
    

    In short, the answer is no, there is no alternative to property() that works in the way you want in the Python standard library.

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

Sidebar

Related Questions

I have 03 models book->target_readers and book has collection. class Book(models.Model): def __unicode__(self): return
I have these models in Django: class Customer(models.Model): def __unicode__(self): return self.name name =
I have models as follows: class Book(models.Model): title = models.CharField(max_length=400) def transactions_all_time(self): latest_transactions =
I have the following IronPython code. class Hello: def __init__(self): pass def add(self, x,
class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
Each book can have many authors. And each author can author many books. class
Here's a simple relational pair of models. class Shelf(models.Model): name = models.CharField(max_length=100) def has_books(self):
I'm trying to do something like this: class AboutView(TemplateView): template_name = 'about.html' def get_context_data(self,
model: class Author{ String name static hasMany = [books: Book] } class Book{ String
Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN

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.