The variable __all__ is a list of public objects of that module, as interpreted by import *. This variable overrides the default of hiding everything that begins with an underscore.
In other words, __all__ is a list of strings defining what symbols in a module will be exported when from <module> import * is used on the module.
For example, the below-mentioned code saved as foo.py explicitly exports the symbols bar and baz:
__all__ = ['bar', 'baz']
waz = 5
bar = 10
def baz():
return 'baz'
So, the two symbols bar and baz can be imported like follows:
from foo import *
print(bar)
print(baz)
# The following will produce an exception, as "waz" is not exported by the module
print(waz)
So, if the above part of the code which contains __all__ is commented out, then this code will be executed to completion, as the default behavior of import * is to import all symbols that do not begin with an underscore, from the given namespace.
Interested to learn more about Python? Come & join our Python online course