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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:14:31+00:00 2026-06-18T02:14:31+00:00

When I define a new-style class in Python, I can get the defined attributes

  • 0

When I define a new-style class in Python, I can get the defined attributes (names and values) by using the __dict__-Attribute, that contains a dictionary of the things.

I’d like to use slots in my classes and their subclasses, because I will created hundreds of thousands of instances and want to save some memory. However, classes that do use __slots__ will not have a __dict__-Attribute so I can not reflectively access their values that way.

Is there another way, preferable one that preserves the order of the attributes defined for such a class?

Any help would be greatly appreciated!

  • 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-18T02:14:32+00:00Added an answer on June 18, 2026 at 2:14 am

    You should use the dir() built-in function to list members of objects instead accessing of either __dict__ or __slots__ directly.

    An instance __dict__ will only list attributes set directly on the instance, while dir() will list attributes (including methods) on the class and bases of that class as well. It’ll also list anything defined as a slot.

    You can use the inspect module to help you filter the output of dir(); if you are not interested in methods for example the inspect.ismethod() can help.

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

Sidebar

Related Questions

In Python 2.7, I define an empty new-style class: In [43]: class C(object): pass
In python 2.x there is some motion to define classes in the new-style class
In Python, the object class serves as the root superclass for all the (new-style)
I know I can define new structs in ruby by doing Person = Struct.new(:first_name,
How can I specifically define a new array of a specific type T ?
I'm trying to define a new array through a where query but I can
I'm trying to define a new shortcode in WordPress, and I get the following
I'm trying to define a new URL handler under OSX that will point at
As I know I can define a new Enum DataFormat at the my project
I'm trying to generate a CSS class that will help me define a page

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.