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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:26:25+00:00 2026-06-04T03:26:25+00:00

Let’s say I have a class like this: class Test(object): prop = property(lambda self:

  • 0

Let’s say I have a class like this:

class Test(object):
    prop = property(lambda self: "property")

The descriptor takes priority whenever I try to access Test().prop. So that will return 'property'. If I want to access the object’s instance storage, I can do:

x = Test()
x.__dict__["prop"] = 12
print(x.__dict__["prop"])

However if I change my class to:

class Test(object):
    __slots__ = ("prop",)
    prop = property(lambda self: "property")

How do I do the same, and access the internal storage of x, to write 12 and read it back, since x.__dict__ no longer exist?

I am fairly new with Python, but I understand the Python philosophy is to give complete control, so why is an implementation detail preventing me from doing that?

Isn’t Python missing a built-in function that could read from an instance internal storage, something like:

instance_vars(x)["prop"] = 12
print(instance_vars(x)["prop"])

which would work like vars, except it also works with __slots__, and with built-in types that don’t have a __dict__?

  • 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-04T03:26:27+00:00Added an answer on June 4, 2026 at 3:26 am

    Short answer, You can’t

    The problem is that slots are themselves implemented in terms of descriptors. Given:

    class Test(object):
        __slots__ = ("prop",)
    
    t = Test()
    

    the phrase:

    t.prop
    

    Is translated, approximately to:

    Test.prop.__get__(t, Test)
    

    where Test.prop is a <type 'member_descriptor'> crafted by the run-time specifically to load prop values out of Test instances from their reserved space.

    If you add another descriptor to the class body definition, it masks out the member_descriptor that would let you get to the slotted attribute; there’s no way to ask for it, it’s just not there anymore. It’s effectively like saying:

    class Test(object):
        @property
        def prop(self):
            return self.__dict__['prop']
    
        @property
        def prop(self):
            return "property"
    

    You’ve defined it twice. there’s no way to “get at” the first prop definition.


    but:

    Long answer, you can’t in a general way. You can

    You can still abuse the python type system to get at it using another class definition. You can change the type of a python object, so long as it has the exact same class layout, which roughly means that it has all of the same slots:

    >>> class Test1(object):
    ...     __slots__ = ["prop"]
    ...     prop = property(lambda self: "property")
    ... 
    >>> class Test2(object):
    ...     __slots__ = ["prop"]
    ... 
    >>> t = Test1()
    >>> t.prop
    'property'
    >>> t.__class__ = Test2
    >>> t.prop = 5
    >>> t.prop
    5
    >>> t.__class__ = Test1
    >>> t.prop
    'property'
    

    But there’s no general way to introspect an instance to work out its class layout; you just have to know from context. You could look at it’s __slots__ class attribute, but that won’t tell you about the slots provided in the superclass (if any) nor will it give you any hint if that attribute has changed for some reason after the class was defined.

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

Sidebar

Related Questions

Let’s say I have a number like 0x448 . In binary this is 0100
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have one class User, and it has a property of type
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say I have some json like this in mongo: {n:5} and a java
Let's say I have this HTML: <div> <div class=ClassA></div> <div class=ClassX></div> <div class=ClassB></div> <div
let's say I have a class that does some calculations. This set of calculations
Let's say I can call a method like this: core::get() . What is the

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.