
Code
Your Public API
Every name in a module can be imported, but not every name is a promise. Python marks the difference with two conventions:
- A leading underscore (
_helper) means "internal, may change without warning". __all__lists the public names. It controlsfrom module import *and tells readers, docs tools and linters what your API is.
# lantern_tools/__init__.py
from .core import light, dim
from ._colors import _blend # internal
__all__ = ["light", "dim"]
Packages often re-export names in __init__.py, so users can write
from lantern_tools import light without knowing which file it lives
in. That gives you freedom to reorganize your files later without
breaking anyone.
Without __all__, a star import grabs every name that doesn't start
with _, including modules you imported, like re.
Assignment
The program writes a module lanternkit.py to the virtual disk. Edit
the module's source text (inside the ''' quotes):
- Rename the helper
clean_colorto_clean_color, everywhere it's used. - Set
__all__to["VERSION", "light"].
The program writes a module lanternkit.py to the virtual disk. Edit
the module's source text (inside the ''' quotes):
- Rename the helper
clean_colorto_clean_color, everywhere it's used. - Set
__all__to["VERSION", "light"].
main.py Python sleeping
Press Run to try your code, then Check to test it.