Importing modules from parent folder

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

    In a Jupyter Notebook

    As long as you're working in a Jupyter Notebook, this short solution might be useful:

    %cd ..
    import nib
    

    It works even without an __init__.py file.

    I tested it with Anaconda3 on Linux and Windows 7.

提交回复
热议问题