Relative imports in Python 3

前端 未结 16 1068
误落风尘
误落风尘 2020-11-21 06:42

I want to import a function from another file in the same directory.

Sometimes it works for me with from .mymodule import myfunction but sometimes I get

16条回答
  •  时光说笑
    2020-11-21 07:04

    I think the best solution is to create a package for your module: Here is more info on how to do it.

    Once you have a package you don't need to worry about relative import, you can just do absolute imports.

提交回复
热议问题