Imagine I have a package "foolibrary" that is installed via setup.py, and I'm the primary developer. Which is the preferred means of calling imports inside the package? Imagine foolibrary has two modules (a.py, b.py) and I need to access them in c.py:
In c.py, what is the preferred way to import these and why?
from a import blah
vs
from foolibrary.a import blah
vs
from .a import blah
I've seen all three and generally use the foolibrary.a import
style, but mostly out of habit.
The relative import syntax, from .a import blah
, is the modern way to do things. See PEP 328, https://www.python.org/dev/peps/pep-0328/ , as to why it's superior to the alternatives. (Though admittedly PEP 8 prefers absolute exports, it also allows within-package relative imports as an acceptable alternative).
Personally, BTW, I always ever import only modules, not "stuff" (functions, classes, whatever) from inside a module.
But, this is a style constraint that is far from universal (it is, however, part of https://google-styleguide.googlecode.com/svn/trunk/pyguide.html -- and having been at Google 10 years now and helped shape parts of its Python practices and style, I'm understandably biased in favor of that style:-).