Application and package of the same name
Skip Montanaro
skip.montanaro at gmail.com
Thu Oct 19 14:18:19 EDT 2017
I'm not understanding something fundamental about absolute/relative
imports. Suppose I have an application, fribble.py, and it has a
corresponding package full of goodies it relies on, also named fribble.
>From the fribble package, the application wants to import the sandwich
function from the lunchtime module. At the top level it thus has an import
like this:
from fribble.lunchtime import sandwich
I might have a directory structure like this:
example
example/fribble.py
fribble
__init__.py
lunchtime.py
If I run inside the example directory with PYTHONPATH=.. I can't
find/import the fribble package, because the main application directory is
prepended to sys.path. Consequently, the import machinery never gets any
further down sys.path. It stumbles on the fribble application and tries to
find the bits it's interested in, to no avail.
This is in Python 2.7, FWIW. What am I missing?
Thx,
Skip
More information about the Python-list
mailing list