Importing modules from parent folder

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

    I made this library to do this.

    https://github.com/fx-kirin/add_parent_path

    # Just add parent path
    add_parent_path(1)
    
    # Append to syspath and delete when the exist of with statement.
    with add_parent_path(1):
       # Import modules in the parent path
       pass
    

提交回复
热议问题