How to import a function to another notebook?

tramtran
Contributor

Could you please provide guidance on the correct way to dynamically import a Python module from a user-specific path in Databricks Repos? Any advice on resolving the ModuleNotFoundError would be greatly appreciated.

udf_check_table_exists notebook:

from pyspark.sql.utils import AnalysisException
import os
import sys

def table_exists(table_name):
    try:
        spark.table(table_name)
        return True
    except AnalysisException:
        return False
 
Error ModuleNotFoundError: No module named 'udf_check_table_exists' with another notebook:
import os
import sys
sys.path.append(os.path.abspath('/Workspace/Repos/[my repo]/dw/common_helper'))

from udf_check_table_exists import table_exists
 

Thank you for your assistance.