0

How can I import a function in a script, where the function is defined in the parent's child folder?

In the following folder structure, I would like to use

root_folder/
    utils_folder:
        __init__.py
        helper_functions.py (where Function_A is defined)
    module_A_folder:
        Script_A.py (Function_A will be imported and used here)
       

Script_A.py needs to use Function_A.

The __init__.py of utils_folder is defined:

from .helper_functions import Function_A

When I tried to import Function_A in Script_A.py like this:

from ..utils import Function_A

I received the following error:

ImportError: attempted relative import with no known parent package

How can I make this work? I am with Python 3.9 x64.

0

1 Answer 1

0

Try:

from utils_folder.helper_functions import Function_A
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I tried it but this threw an error of ModuleNotFoundError: No module named 'utils_folder'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.