What is all in Python?
Please explain what __all__
is (as I understand it, it is a list), in which cases it is used in Python, and how it is used when importing?
I read Beazley, but it is somehow written in a complicated way and the example is incomprehensible, I did not understand, to be honest. Googling didn't help much either...
1 answers
__all__
in Pythone , this is a list of public objects of this module. I.e., let's say you have a certain mymodule.py, it describes a lot of objects, and you do not need to give them all to use from the outside. In __all__
in mymodule.py you define the names of objects that can be imported (__all__ = ["MyClass", "MyClass2"]
) in a list.
I.e., for example, when from mymodule import *, only the objects that you described in __all__
will be imported.
Perhaps the __all__
directive should be correctly named as one of the levels encapsulations in Python.