There's something I completely dislike when importing a module in an interactive Python shell, typing the name of the module, hitting tab and getting the automatic completion cluttered with other modules that the module itself had imported (but are internal implementation details that are not really useful for me).
Example:
a.py
import os
import datetime
def foo():
now = datetime.datetime.now()
print os.path.join(map(str, (now.year, now.month, now.day)))
shell
$ ipython
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import a
In [2]: a.
a.datetime a.py
a.foo a.pyc
a.os
I don't care that module a depends on datetime and os, that is distracting me from what the module provides (foo).
So I have started to make my imports private, like this:
a.py
import os as _os
import datetime as _datetime
def foo():
now = _datetime.datetime.now()
print _os.path.join(map(str, (now.year, now.month, now.day)))
shell
$ ipython
iPython 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import a
In [2]: a.
a.foo
a.py
a.pyc
Is this considered pythonic at all? I feel like it's a little bit too verbose, but I think simplifying the end user's experience should be above saving some extra tokens per import.