Assuming I want to hide all implementation details of a module, and even adding an underscore [1][2] is not enough, are there practical (or pythonistic) reasons against using del
?
mymod/__init__.py
import time
# m2.py with def tock(): ...
from . import m2 as tick
since_epoch = time.time
summer = time.daylight
# def myfn():
# return time.ctime() # this fails of course
del time
del m2
__all__ = ['since_epoch', 'summer']
This way dir(mymod)
only shows the API and mymod.tick.tock()/since_epoch()
are usable. (Well, almost: mymod.tick
betrays the fact that it was once called m2
.)
This is useful to only show relevant suggestions in the interactive python shell, see python3 -i -c "import mymod; print(dir(mymod))"
then >>> mymodule.<TAB>
.
1: Hide external modules when importing a module (e.g. regarding code-completion) / 2: Python: 'Private' module in a package