python 根据路径导入模块

Import python module NOT on path


常规做法:
[python] view plain copy
  1. import sys  
  2. sys.path.append('C:/full/path')  
  3. from foo import util,bar  

而要直接通过路径
[python] view plain copy
  1. import imp  
  2. util = imp.load_source('util', 'C:/full/path/foo/util.py')  

使用时使用util.method,此时并没有定义method 

method = util.method后才可以直接用method

原文地址:https://www.cnblogs.com/yanzi-meng/p/7909728.html