def importer (directory, libpath, module = None):
fn = not libpath.endswith (".py") and libpath + ".py" or libpath
modpath = os.path.join (directory, fn)
hname = fn.split (".")[0]
p = directory.replace ("\\", "/")
if p.find (":") !=- 1:
p = "/" + p.replace (":", "")
while 1:
if "skitai.mounted." + hname in sys.modules:
p, l = os.path.split (p)
if not l:
raise SystemError ('module %s already imported, use reload')
hname = l + "." + hname
else:
hname = "skitai.mounted." + hname
break
loader = importlib.machinery.SourceFileLoader(hname, modpath)
mod = loader.load_module ()
return mod, mod.__file__
评论列表
文章目录