What does "from module import *" do, and what is __all__?
import * brings every public name of a module into your namespace, which can silently overwrite existing names. A module can control what it exports by defining __all__, a list of names. Without __all__, names starting with an underscore are skipped.
Explain it simply
Taking everything from a shared stationery cupboard in one grab means you may swap your own good pen for a worse one with the same label. Taking items by name is safer and shows what you use. __all__ is the shopkeeper's notice, "only these items are for public sale".
Example
# shapes.py
__all__ = ["area"]
PI = 3.14
def area(r):
return PI * r * r
def _secret():
return "hidden"# main.py
from shapes import *
print(area(2)) # 12.56
print("PI" in dir()) # False: not in __all__If shapes.py had no __all__, PI would be imported but _secret would not, since it begins with an underscore. Importing * also makes it hard to tell where a name came from, and tools like linters complain about it.
What to say in the interview
"import copies all public names into the current namespace, which risks overwriting names and hides where things come from, so I avoid it outside the REPL. __all__ defines a module's public API, and it's what import and documentation tools respect. I use explicit imports in real code."