How to do relative imports in Python?

前端 未结 15 2812
情深已故
情深已故 2020-11-21 04:47

Imagine this directory structure:

app/
   __init__.py
   sub1/
      __init__.py
      mod1.py
   sub2/
      __init__.py
      mod2.py

I\'

15条回答
  •  借酒劲吻你
    2020-11-21 05:41

    Take a look at http://docs.python.org/whatsnew/2.5.html#pep-328-absolute-and-relative-imports. You could do

    from .mod1 import stuff
    

提交回复
热议问题