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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:32:01+00:00 2026-06-15T13:32:01+00:00

In Python, the dir() function is used to display a list of attributes, classes,

  • 0

In Python, the dir() function is used to display a list of attributes, classes, methods of the argument which is passed in to it, right ?

For example there is a module email in python

import email
dir(email)

Result:

['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header', 'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_name', 'base64MIME', 'email', 'importer', 'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys']

So what I want to know is how to tell whether a given object in the above list is an attribute, method, class, or function.

From the above list, we can expect that __all__, __builtins__, __doc__, etc. are attributes, but how can we differentiate all/remaining of these types just by looking at the list?

  • 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-15T13:32:03+00:00Added an answer on June 15, 2026 at 1:32 pm

    They’re all attributes, some of those attributes might reference functions, some classes, or objects. The ones like __this__ are commonly called magic methods.

    You can look at:

    [type(getattr(email, x)) for x in dir(email)]
    

    But the best answer is: “What do I care?”

    Any information you need to know about the interface is better found in the documentation of the module. The types of various attributes are of little use, low importance (and dir can be incomplete, too).

    So don’t bother type checking. It is worth knowing (and using) the python naming conventions though (see pep8):

    • CamelCase for classes
    • snake_case for functions and methods
    • SHOUTY_CASE for constants
    • _leading underscores for ‘private’ things (i.e. undocumented, implementation detail, not intended to be part of public interface)
    • __double leading underscores for enabling name mangling, it’s a way to handle possible namespace collisions in complex inheritance situations (a very obscure feature that you almost certainly don’t need in normal usage)
    • __dunder__ “double underscore” things for magic methods as mentioned previously, these are datamodel hooks for Python itself. You can redefine existing hooks to customize behaviour in your classes and modules, but don’t invent new magic names just for your own purposes, use normal attributes instead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python there is a built-in function called dir . This is used to
The dir() function in python retrieves all attributes for a class. I was wondering
Python comes with the handy dir() function that would list the content of a
How come the dir() function in Python doesn't show all of the callable attributes?
I'm using a python generator function to provide me with a list of images
In python how can I create a function that can be global an used
My python program has many function which all seem to work fine when run
I am working on my first large python project. I have one function which
How can I get the list of class functions from within __getattr__ function? Python
when I write Python code from the interpreter I can type dir() to have

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.