Using __init__.py

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

Today I started using pyzmq, and I wanted to see what happens behind the scenes. So I looked at the code on github and found (for me) some weird use __init__.pythere that I cannot explain myself.

For example zmq/core/__init__.py. What is the point of adding to the zmq.core.__all__values __all__ zmq.core.constants, zmq.core.error, zmq.core.message, etc.?

As zmq/__init__.pyI see the end

__all__ = ['get_includes'] + core.__all__

where get_includesis a function that basically returns a list with the module directory and the utils directory in the parent directory.

What's the point? What __init.py__did you accomplish by doing this?

+5
source share
1 answer

__all__ , from module import * .

- . import : __init__.py __all__, , , * . , . , * . , sounds/effects/__init__.py :

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

, from sound.effects import * .

__all__ - , , , . , pyzmq , :

import zmq
print zmq.zmq_version()

, :

print zmq.core.version.zmq_version()

pyzmq __all__ , .

+11

All Articles