Howto import modules with dependencies in the same absolute/relative path with imp?

前端 未结 2 986
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 15:31

Is there a way to import modules with dependencies within the same directory using an absolute/relative path with \"imp\" ?

Here follows the directory structure:

2条回答
  •  旧时难觅i
    2021-01-11 16:23

    IMO this is not feasible with load_source which doesn't do necessary things so that import in your 'dependant.py' file consider its parent directory.

    You should either do what have been suggested (__init__.py in the directory and absolute import in the module), or use lower-level find_module / load_module functions which allows this kind of things (see find_module 'path' argument)

提交回复
热议问题