How to import a Python module given the full path?

PythonServer Side ProgrammingProgramming

The easiest way to import a Python module, given the full path is to add the path to the path variable. The path variable contains the directories Python interpreter looks in for finding modules that were imported in the source files.

For example

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
raja
Published on 26-Dec-2017 12:45:27
Advertisements