Python Open File relatif terhadap modul
import os
TEST_FILENAME = os.path.join(os.path.dirname(__file__), 'test.txt')
Good Goshawk
import os
TEST_FILENAME = os.path.join(os.path.dirname(__file__), 'test.txt')
# If the module is in the same directory:
import <module_name>
# If the module isn't in the same directory:
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')
import <module_name>
import sys
sys.path.append('/foo/bar/my_module')
# Considering your module contains a function called my_func, you could import it:
from my_module import my_func
# Or you could import the module as a whole,
import my_module
import sys
sys.path.append("") # fixes import issues
from your_file import your_class
# OR
from your_dir.your_file import your_class
# also, make sure there is an empty __init__.py file in each directory
import os, sys
sys.path.append('../package1/module1.py')
from application.app.folder.file import func_name