ImportError - cannot import other python files

I tried to modularize my code by splitting code into various python files and importing in __init__.py. However, I am encountering ImportError when I did that.

As an example, my skill directory is as follows:

/my-mycroft-skill
– /dialog
– /vocab
__init__.py
– test.py
– …

Where inside test.py I defined a function called fib.

When I add the line import test in __init__.py the skill loaded normally. But when I tried to call test.fib it raises an import error, saying it cannot find fib. Similarly, when I tried from test import fib, I also get an import error, saying:

ImportError: cannot import name ‘fib’ from ‘test’

Could someone help me with this? I can’t figure out why this doesn’t work. Thanks in advance!

I have seem to found the solution. The importing syntax is a little different. We must use

from . import (test)

to import the module. If the module file is located inside a subfolder, say, lib. Then we must import it by

from .lib import (test)