Best Answer · By JanBask Python Expert
Answered on Mar 3, 2021
The variable __all__ is a rundown of public objects of that module, as deciphered by import *. This variable abrogates the default of concealing all that starts with an underscore.
As such, __all__ is a rundown of strings characterizing what images in a module will be sent out when from import * is utilized 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.