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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:21:30+00:00 2026-06-11T16:21:30+00:00

I use __init__.py to run checks when I do from myprojects.something import blabla .

  • 0

I use __init__.py to run checks when I do from myprojects.something import blabla.

Today I started using pyzmq and I wanted to see what’s going on behind the scenes. So I browsed the code in github and I find (for me) some strange usage of __init__.py there that I cannot explain myself.

For example zmq/core/__init__.py. What’s the point of adding in zmq.core.__all__ the __all__‘s value of zmq.core.constants, zmq.core.error, zmq.core.message, etc.?

In zmq/__init__.py I see at the end

__all__ = ['get_includes'] + core.__all__

where get_includes is a function which basically returns a list with the directory of the module and the utils directory in the parent directory.

What’s the point of that? What has __init.py__ achieved by doing that?

  • 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-11T16:21:31+00:00Added an answer on June 11, 2026 at 4:21 pm

    The __all__ is for when someone does from module import * as documented here.

    The only solution is for the package author to provide an explicit
    index of the package. The import statement uses the following
    convention: if a package’s __init__.py code defines a list named
    __all__, it is taken to be the list of module names that should be imported when from package import * is encountered. It is up to the
    package author to keep this list up-to-date when a new version of the
    package is released. Package authors may also decide not to support
    it, if they don’t see a use for importing * from their package. For
    example, the file sounds/effects/__init__.py could contain the
    following code:

    __all__ = ["echo", "surround", "reverse"]
    

    This would mean that from sound.effects import * would import the
    three named submodules of the sound package.

    One use for __all__ is a tool for package builders to allow them to structure their package in a way that works for them while making it convenient for users. Specifically in the case of pyzmq, it lets you write code such as:

    import zmq
    print zmq.zmq_version()
    

    Rather than having to use the full dotted module name:

    print zmq.core.version.zmq_version()
    

    The package designers of pyzmq are using __all__ to promote namespace elements from nested modules up to the top level of their namespace so the user isn’t bothered by the structure of their package.

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

Sidebar

Related Questions

I'm using swank-clojure from https://github.com/technomancy/swank-clojure . I'd like to run clojure-jack-in automatically when a
Why isn't viewDidUnload method called, when I'm not using xib and use alloc/init to
when I use MySQLdb get this message: /var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
I have used cakePHP 1.2 and know how to use behaviors in it. using
I'm using SQL Server and I want to use identity constraint in it I
In our company we have started using VS 2010 to model our systems, in
I've run into a strange problem where a huge number of messages from snmplib's
I want to run a web application on php and mysql, using the CakePHP
I want to use ALAssetsLibrary framework for displaying photos from the photo album.But while
i am recording video from webcam using DirectshowLib2005.dll in C#.net..i have this code to

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.