Importing modules from parent folder

前端 未结 22 2725
梦毁少年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:49

    Though the original author is probably no longer looking for a solution, but for completeness, there one simple solution. It's to run life.py as a module like this:

    cd ptdraft
    python -m simulations.life.life
    

    This way you can import anything from nib.py as ptdraft directory is in the path.

提交回复
热议问题