How to import a module in Python with importlib.import_module

前端 未结 3 1703
臣服心动
臣服心动 2020-11-28 08:19

I\'m trying to use importlib.import_module in Python 2.7.2 and run into the strange error.

Consider the following dir structure:

    a
    |
    + - __ini         


        
3条回答
  •  独厮守ぢ
    2020-11-28 08:50

    For relative imports you have to:

    • a) use relative name
    • b) provide anchor explicitly

      importlib.import_module('.c', 'a.b')
      

    Of course, you could also just do absolute import instead:

    importlib.import_module('a.b.c')
    

提交回复
热议问题