Python's method of importing modules by path

  • 2020-04-02 14:12:44
  • OfStack

This article illustrates the python method of importing modules according to the path. Specific methods are as follows:

The general practice is as follows:


import sys 
sys.path.append('C:/full/path') 
from foo import util,bar 

You want to go directly through the path


import imp 
util = imp.load_source('util', 'C:/full/path/foo/util.py') 

Util.method is used without a method defined
Method = util. Method can be used directly after method

I hope this article has helped you with your Python programming.


Related articles: