import inspect
inspect.ismodule(module_name)
python
|--main.py
|articles
|--gfg.py
# class
class GFG:
# method
def method_in():
print("Inside Class method")
# explicit function
def method_out():
print("Inside explicit method")
# importing module
import sys
# appending a path
sys.path.append('articles')
# importing required module
import gfg
from gfg import GFG
# accessing its content
GFG.method_in()
gfg.method_out()
import importlib.util
# specify the module that needs to be
# imported relative to the path of the
# module
spec=importlib.util.spec_from_file_location("gfg","articles/gfg.py")
# creates a new module based on spec
foo = importlib.util.module_from_spec(spec)
# executes the module in its own namespace
# when a module is imported or reloaded.
spec.loader.exec_module(foo)
foo.GFG.method_in()
from importlib.machinery import SourceFileLoader
# imports the module from the given path
foo = SourceFileLoader("gfg","articles/gfg.py").load_module()
foo.GFG.method_in()
foo.method_out()