klaas
New Contributor II
This works as long as the script calling the module is indeed __main__; i've changed it a bit to make it more generic:
import os
import sys

def find_module(path):
    while path:
        if os.path.basename(path) == "src":
            return path
        new_path = os.path.abspath(os.path.join(path, '..'))
        if new_path == path:  # Prevent infinite loop
            break
        path = new_path
    return None

# Start from the current directory
current_directory = os.getcwd()

# Find the source directory
source_directory = find_module(current_directory)

if source_directory:
    sys.path.append(source_directory)
    from src.core import MyModule
else:
    raise ImportError("Databricks messed up my filepaths. Please complain somewhere.")