Home python What is __all__ in Python?

What is __all__ in Python?

Author

Date

Category

Explain, please what __ all __ (I understand that this is a certain list), in what cases is it used in Python and how is it applied when importing?

I read bizli, but there is somehow it is written and the example is incomprehensible, I did not understand, honestly. The googling also did not particularly help …


Answer 1, Authority 100%

__ All __ In Pythone, this is a list of public objects of this module. Those, let’s say, you have some myModule.py, it describes a lot of objects, and it is not necessary to use them by everyone. In __ ALL __ in mymodule.py, you define the names of objects that can be imported (__ All__ = ["MyClass", "MyClass2"] ).
Those., For example, from from MyModule Import * only those objects that you described in __ ALL __ are imported.
Perhaps the __ all __ directive will correctly call one of the levels of encapsulation in Python.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions