As @Davidism mentioned in the comments above you would import the files " The same way you import anywhere else. Import paths are separated by dots, not slashes."
Let's say you have a file structure like this
/Project
--program.py
/SubDirectory
--TestModule.py
In this example let's say that the contents of TestModule.py
is:
def printfunction(x):
print(x)
Now let's begin first, in your program.py
you need to import sys
then add your subdirectory to python's environment paths using this line of code
import sys
sys.path.insert(0, os.getcwd()+"/SubDirectory")
Now you can import the module as normal. Continuing with the file structure described above you would now import the module like so
import TestModule
You can now call the function printfunction()
from the TestModule.py
file just like normal
TestModule.printfunction("This is a test! That was successful!");
This should output:
This is a test! That was successful!
All in all your program.py
file should look like this:
import sys
sys.path.insert(0, os.getcwd()+"/SubDirectory")
import TestModule
TestModule.printfunction("This is a test! That was successful!");