In a certain programme I have an abstract class that should be implemented in two different sub-packages for different purposes. A simplified version of this structure is:
programme/
__init__.py
Abstract.py
pkgA/
__init__.py
ClassA.py
pkgB/
__init__.py
ClassB.py
Up to Python 3.2 (I believe), it was possible to import the Abstract class within the a subfolder with a relative reference:
from .. import Abstract
Which with Python 3.6 devolves the error message:
ValueError: attempted relative import beyond top-level package
The classical (and ugly) alternative is to add the parent folder to the path at run time:
import sys
import os
sys.path.append(os.getcwd() + '/..')
from programme import Abstract
But this also fails:
ModuleNotFoundError: No module named 'programme'
How is this now done with Python 3.6? Preferably without modifying the path at run time.