How to import a module given the full path?

Answer

There are equivalent convenience functions for compiled Python files and DLLs.

For Python 3.3+ this is a bit more involved, unfortunately:

import importlib.machinery

loader = importlib.machinery.SourceFileLoader("module.name","/path/to/file.py")
foo = loader.load_module()
foo.MyClass()

All python Questions

Ask your interview questions on python

Write Your comment or Questions if you want the answers on python from python Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---