Importing a module dynamically using imp

前端 未结 2 516
谎友^
谎友^ 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:26

    Appears to be a simple pathing problem - check __file__ or cwd... Maybe try an absolute file path first? - This imp example may help.

    0 讨论(0)
  • 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")
    
    0 讨论(0)
提交回复
热议问题