Import module from a different subdirectory

Inada Naoki songofacandy at gmail.com
Fri May 17 01:25:55 EDT 2019


2019年5月17日(金) 9:25 Rich Shepard <rshepard at appl-ecosys.com>:
>
> My understanding is that Python3 does not require subdirectories to have an
> __init__.py file, only Python2 does. If that's not correct I'll add the
> blank file.
>

This is slightly off topic (not relating to your problem), but please don't
think "Python 3 doesn't require __init__.py for packages".
It is common misunderstanding.

Package directory without __init__.py is "namespace package".
Namespace package is not a regular package.  See [1] for detail.

[1]: https://packaging.python.org/guides/packaging-namespace-packages/

There are some difference between regular package and namespace package.
They have different module search order.  Testing tools including unittest
doesn't search namespace package.  (If they do, they may take minutes
to search million files in `node_modules` directory in your project!)
So abusing namespace package will bite you at some point.


Regards,
-- 
Inada Naoki  <songofacandy at gmail.com>


More information about the Python-list mailing list