目录层级如下:
[root@localhost auto]# tree
.
├── bin
│ ├── __init__.py
│ ├── publish
│ │ ├── __init__.py
│ │ └── test.py
│ ├── ros
│ │ ├── __init__.py
│ │ └── ros.py
│ └── test.py
├── controllers
│ ├── Apiactions.py
│ └── __init__.py
├── __init__.py
├── public
│ ├── conf
│ │ └── __init__.py
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── library
│ │ ├── Gitclone.py
│ │ ├── __init__.py
│ │ └── Print.py
│ ├── modules
│ │ └── __init__.py
│ ├── test.py
│ └── test.pyc
├── tmp
│ ├── gitwarehouse
│ │ └── __init__.py
│ └── resources
│ └── __init__.py
└── ymlmodules
└── publish
目的:在 bin/publish/test.py 中导入 public/library/Print.py
原来做法两层目录够用:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
现在多一层次导入失败
[root@localhost auto]# tree
.
├── bin
│ ├── __init__.py
│ ├── publish
│ │ ├── __init__.py
│ │ └── test.py
│ ├── ros
│ │ ├── __init__.py
│ │ └── ros.py
│ └── test.py
├── controllers
│ ├── Apiactions.py
│ └── __init__.py
├── __init__.py
├── public
│ ├── conf
│ │ └── __init__.py
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── library
│ │ ├── Gitclone.py
│ │ ├── __init__.py
│ │ └── Print.py
│ ├── modules
│ │ └── __init__.py
│ ├── test.py
│ └── test.pyc
├── tmp
│ ├── gitwarehouse
│ │ └── __init__.py
│ └── resources
│ └── __init__.py
└── ymlmodules
└── publish
目的:在 bin/publish/test.py 中导入 public/library/Print.py
原来做法两层目录够用:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
现在多一层次导入失败