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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:09:17+00:00 2026-05-23T20:09:17+00:00

Can anybody explain to me with adequate examples whats the difference b/w >>> import

  • 0

Can anybody explain to me with adequate examples whats the difference b/w

>>> import inspect
>>> inspect.getmembers(1)

and

>>> type(1).__dict__.items()

and

>>> dir(1)  

except that they show an decreasing no.s of attributes & methods in that order.
1 is integer (but it can be of any type.)


EDIT

>>>obj.__class__.__name__  #gives the class name of object  
>>>dir(obj)                #gives attributes & methods  
>>>dir()                   #gives current scope/namespace
>>>obj.__dict__            #gives attributes
  • 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-05-23T20:09:18+00:00Added an answer on May 23, 2026 at 8:09 pm

    dir() allows you to customize what attributes your object reports, by defining __dir__().

    From the manual, if __dir__() is not defined:

    If the object is a module object, the list contains the names of the module’s attributes.

    If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases.

    Otherwise, the list contains the object’s attributes’ names, the names of its class’s attributes, and recursively of the attributes of its class’s base classes.

    This is also what inspect.getmembers() returns, except it returns tuples of (name, attribute) instead of just the names.

    object.__dict__ is a dictionary of the form {key: attribute, key2: atrribute2} etc.

    object.__dict__.keys() has what the other two are lacking.

    From the docs on inspect.getmembers():

    getmembers() does not return metaclass attributes when the argument is a class (this behavior is inherited from the dir() function).

    For int.__dict__.keys(), this is

    ['__setattr__', '__reduce_ex__', '__reduce__', '__class__', '__delattr__', '__subclasshook__', '__sizeof__', '__init__']
    

    To summarize, dir() and inspect.getmembers() are basically the same, while __dict__ is the complete namespace including metaclass attributes.

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

Sidebar

Related Questions

Can anybody explain the idea behind JSP custom tag libraries and the JSP 2
Can anybody explain why the name Decorator was chosen for the functionality conveyed by
Can anybody please explain how this could possibly happen? I am completely aware of
Can anybody explain why do you need to return a reference while overloading operators
Can anybody explain to me the cause of the following message, perhaps along with
Can anybody explain what's wrong? I have row[i] that is boxed decimal and when
Can anybody explain how this line works? return $y < 0 ? - pip2
Can anybody explain what this error means: The .Net Framing mode being used is
can anybody explain me the below code for trigger?Please note that the above code
can anybody explain me with simple example to handle Monitor.PulseAll().I have already gone some

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.