Error when importing a whole subfolder with submodules with __init__ file

39 views Asked by At

I have the following structure:

folderA
├── __init__.py
└── folderB
    ├── __init__.py
    └── folderC
        ├── __init__.py
        └── module.py

I want to be able to import folderC without having to call folderB, like the following way:

from folderA.folderC.module import *

And I have written the following things in the files:

folderA/__init__.py:

from .folderB import *

folderA/folderB/__init__.py:

# empty

folderA/folderB/folderC/__init__.py:

from .module import hello

folderA/folderB/folderC/module.py:

def hello():
  print("hello world")

But I received the following error message:

ModuleNotFoundError: No module named 'folderA.folderC'

How can I import folderC without having to name folderB in the process?

0

There are 0 answers