I'm building a package that contains scripts to be run. They import modules contained in a subfolder directly under the script. Now that __init__
is not required after Python 3.3, what's the correct file structure and import
statement to have? I'd like to not have to specify the import from the topmost folder down, only as a relative path, here sub/module
.
This is the current state of the file structure:
Root\
src\
sub\
module.py
script.py
parent_module.py
setup.py
# Inside script.py
import sub.module # Doesn't work
from sub import module # Doesn't work
import src.sub.module # Does work!
import .sub.module # Doesn't work
import .parent_module # Does work!
I imagine I need to have some __init__
file, but what and where would that be? Any help is greatly appreciated, I don't know much about packaging.
Also, I'm certainly open to suggestions to changing the structure, if that makes things easier.