Last active
November 22, 2018 06:02
-
-
Save ayuLiao/5b1c880f634882188eb9db4aae29e887 to your computer and use it in GitHub Desktop.
python程序中使用 import XXX 时,python解析器会在当前目录、已安装和第三方模块中搜索 xxx,如果都搜索不到就会报错。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 加入上层目录和绝对路径 | |
| ''' | |
| import sys | |
| sys.path.append('..') #表示导入当前文件的上层目录到搜索路径中 | |
| sys.path.append('/home/model') # 绝对路径 | |
| from folderA.folderB.fileA import functionA | |
| ''' | |
| 加入当前目录 | |
| ''' | |
| import sys | |
| sys.path.append(os.getcwd()) | |
| ''' | |
| 定义搜索优先顺序 | |
| ''' | |
| import sys | |
| sys.path.insert(1, "./model") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment