I have this file setup:
mainfolder:
__init__.py
mainfile.py
subfolder1:
file1.py
__init__.py
subfolder2:
file2.py
__init__.py
I need to import mainfile.py into file1.py and file2.py. Currently I am using:
from .. import mainfile
However this brings the error: attempted relative import beyond top level package.
I have also tried:
from ...mainfolder import mainfile
Which brings up the same message, and:
from mainfolder import mainfile
Which brings the error message: no module named 'mainfolder'
Within the __init __.py files I have this code:
__all__ = [list of files in package]
I'm not sure why this is not working. I would greatly appreciate it if someone could explain what I am doing wrong.
EDIT: The error "Attempted relative import beyond top-level package" occurred when I ran:
from .. import mainfile
within file 1.