Relative imports in Python 3

前端 未结 16 1056
误落风尘
误落风尘 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:28

    if both packages are in your import path (sys.path), and the module/class you want is in example/example.py, then to access the class without relative import try:

    from example.example import fkt
    

提交回复
热议问题