Importing a module dynamically using imp

前端 未结 2 517
谎友^
谎友^ 2020-12-09 03:56

I am trying to import a module from a different directory dynamically. I am following an answer from this question. I have a module named bar in a directory named foo. The m

2条回答
  •  独厮守ぢ
    2020-12-09 04:33

    imp.load_source requires the pathname + file name of the module to import, you should change your source for the one below:

    mod = imp.load_source("bar","./foo/bar.py")
    

提交回复
热议问题