Importing modules from parent folder

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

    same sort of style as the past answer - but in fewer lines :P

    import os,sys
    parentdir = os.path.dirname(__file__)
    sys.path.insert(0,parentdir)
    

    file returns the location you are working in

提交回复
热议问题