How to properly use relative or absolute imports in Python modules?

前端 未结 6 1480
我在风中等你
我在风中等你 2020-12-02 20:30

Usage of relative imports in Python has one drawback, you will not be able to run the modules as standalones anymore because you will get an exception: ValueError: Att

6条回答
  •  伪装坚强ぢ
    2020-12-02 21:27

    So far the only solution I found was not to use relative imports at all.

    Due to current limitation, I'm wondering when someone is supposed to use relative imports in python.

    On all configurations that I used the sys.path contained the current directory as first argument so just use import foo instead of from . import foo because it will do the same.

提交回复
热议问题