Importing modules from parent folder

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

    Here is more generic solution that includes the parent directory into sys.path (works for me):

    import os.path, sys
    sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
    

提交回复
热议问题