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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:15:33+00:00 2026-06-02T00:15:33+00:00

Every class in python inherits from the class ‘object.’ I am wondering about the

  • 0

Every class in python inherits from the class ‘object.’ I am wondering about the internal mechanism of the ‘object’ class implementation. Why cannot the ‘object’ class be assigned any user-attributes? I am convinced that it is related to memory-management but what if the user thinks of implementing the memory-management himself, why can’t he override ‘object’ class in python? This is based on my interest and want to know about which might not have any programmatic application but would be nice to know the internal feature of the language itself.

  • 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-02T00:15:35+00:00Added an answer on June 2, 2026 at 12:15 am

    If I had to derive the reasoning from first principles, I might think about it in terms of the __slots__ mechanism. Some kinds of classes only need a tiny number of attributes, and the set of attributes is always fixed for every instance, and so the flexibility of a “dict” like user attributes capability would be wasteful of cpu (looking up dynamically named attributes) and space (the overhead of an empty dict, small but non-zero), which can really add up to a lot of overhead if there are a large number of instances.

    of course this is exactly the problem the __slots__ mechanism solves. space is allocated on the object for the attributes defined in slots. if there’s a __dict__ attribute, non-slot attributes can be found there, and if there’s no __dict__ attribute, you get neither the dynamic attributes nor the cost of the unneeded dict object (which is an additional heap object other than the instance itself).

    As for why object itself does not have a slot for __dict__, well, even if a subclass indicated that they didn’t need the __dict__ slot, if they inherit from a class that does, then the instance must still have a __dict__; if object had a __dict__ then absolutely every class would also pay the price of having a __dict__, even if they didn’t need it.

    Instead; subclasses get __dict__ (and __weakref__, for analogous reasons) unless they themselves define a __slots__ class attribute.

    And why would you need a plain-ol instance of object at all? Do you just need a bag of attributes? well then use a dict. If you actually need an object of some kind with behaviors and attributes, then you are making a subclass anyways.

    About the only reason I can ever imagine using object() instead of a subclass of object, is when the only feature of the instance that is of interest is its identity. This would come up when a function takes arguments, and for which None or some other obvious sentinel value should be understood as distinct from the default:

    BAR_DEFAULT = object()
    def foo(bar=BAR_DEFAULT):
        if bar is BAR_DEFAULT:
            #...
    

    In which case you neither need nor particularly want attributes on the instance of object,

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

Sidebar

Related Questions

Since every class inherits the initializer from the superclass this is how I have
Every object I know of in Python can take care of its base class
I am wondering if maybe ReSharper is able to run through every class and
For every use I can think of for Python's itertools.repeat() class, I can think
In Python, the object class serves as the root superclass for all the (new-style)
In JavaScript, every object is at the same time an instance and a class.
With a class in Python, how do I define a function to print every
According to, http://www.freshvanilla.org:8080/display/www/Java+Interview+Questions Under Which class is the superclass of every class? null seems
Instead of individually calling $(#item).removeClass() for every single class an element might have, is
Is this good OO Design assuming you want every inheriting class to be a

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.