Home > Article > Backend Development > Nested directories and classes in python libraries
There are several nested directories in this library I'm building, some nested directories have no files but others don't, or each directory has one or more class files.
The library is basically ported from another language and I have to keep the structure the same.
I'm looking for code organization and module access without duplication in import statements
mylib ├── foo │ ├── bar │ └── baz.py (class baz) ├ test ── foo ├── bar ── test_baz.py
The problem I have is the duplication in the import statement
from mylib.foo.bar.baz import baz
Is there any way to avoid .baz
appearing in the import statement?
In the __init__
file, I've tried this without any real effect.
import baz.baz import Baz __all__ = [ "Baz" ]
You can use from .baz import Baz# in
mylib/foo/bar/__init__.py ##.
The above is the detailed content of Nested directories and classes in python libraries. For more information, please follow other related articles on the PHP Chinese website!