About __all__ in python

When I was studying python before, I mentioned __all__, but I'm starting to wonder what it is recently, so I'll make a note of it.

__all__ is what you write in the __init__.py file. So all the strings you write in all will be imported when this python module is imported.

So, with from package import *, the function of the previous string in this package will be imported. Other than that, it will not be imported.

It was that. that's all

By the way, from package import * is a very disliked writing style, so be careful not to use it as much as possible.

The following is the answer when asked by the overseas community that I referred to. The outline is written above, so please have a look if you are interested.

__all__ is a variable that can be set in the __init__.py file of a package.

The __all__ variable is a list of strings which defines those symbols that are imported when a program does

from package import * If the __all__ for this package was set as follows:

all = ['echo', 'effect', 'reverb']

then
from package import *

would be equivalent to

from package import echo
from package import effect
from package import reverb

Note that using from <package> import * is considered bad style in production code, since you have no control over what >you are importing and what your import might shadow.

for more information see : 6. Modules - Python 3.8.2 documentation

Recommended Posts

About __all__ in python
Think about architecture in python
About "for _ in range ():" in python
About dtypes in Python and Cython
I learned about processes in Python
About python slices
Quadtree in Python --2
Python in optimization
About python comprehension
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
About Python tqdm.
Unittest in python
About python, class
Epoch in Python
Discord in Python
Sudoku in Python
nCr in python
N-Gram in Python
About python inheritance
Programming in python
About python, range ()
Plink in Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
About python reference
Puyo Puyo in python
python in virtualenv
PPAP in Python
About Python decorators
[Python] About multi-process
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
[Python] Combine all the elements in the array
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
About Python for loops
Daily AtCoder # 18 in Python
Summary about Python scraping
Singleton pattern in Python