Importing modules from parent folder

前端 未结 22 3205
梦毁少年i
梦毁少年i 2020-11-21 23:19

I am running Python 2.5.

This is my folder tree:

ptdraft/
  nib.py
  simulations/
    life/
      life.py

(I also have __init

22条回答
  •  孤街浪徒
    2020-11-21 23:53

    You could use relative imports (python >= 2.5):

    from ... import nib
    

    (What’s New in Python 2.5) PEP 328: Absolute and Relative Imports

    EDIT: added another dot '.' to go up two packages

提交回复
热议问题