in Education by
I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files. Can someone explain what this does? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
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 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

Related questions

0 votes
    I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't ... ++/-- notation? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    What * and ** do for param2 in the following: def foo(param1, *param2): def bar(param1, **param2): Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Coming from a C# background the naming convention for variables and method names are usually either Camel Case or ... for Python? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible ... the underlying database? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have drawn an image in the device context using python and I want to move it smoothly/animate either ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have drawn an image in the device context using python and I want to move it smoothly/animate either ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have drawn an image in the device context using python and I want to move it smoothly/animate either ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    How can I do the following in Python? array = [0, 10, 20, 40] for (i = array.length() - 1; i >= ... but from the end to the beginning. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I would like to get a list of Python modules, which are in my Python installation (UNIX server). How can ... in your computer? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how I can represent the equivalent of an Enum in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I remove the last character of a string in a newline, In perl I used chomp function what's equivalent to that in Python? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to put time delay in the script of Python? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me where can I learn Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
...