1. 程式人生 > >os.path與sys.path的區別

os.path與sys.path的區別

os.path 和 sys.path 區別
os.path 主要是用於對系統路徑檔案的操作。
sys.path 主要是對 Python 直譯器的系統環境引數的操作(動態的改變 Python 直譯器搜尋路徑)。
import sys ,os
caffe_root="/usr/local/caffe/"
sys.path.insert(0,caffe_root+"python")
print(sys.path)
print(os.path)

結果如下

['/usr/local/caffe/python', '/usr/local/caffe/python', '', '/usr/local/caffe/python', '/storage/st2/code/deepdream', '/storage/st2/anaconda2/lib/python27.zip', '/storage/st2/anaconda2/lib/python2.7', '/storage/st2/anaconda2/lib/python2.7/plat-linux2', '/storage/st2/anaconda2/lib/python2.7/lib-tk', '/storage/st2/anaconda2/lib/python2.7/lib-old', '/storage/st2/anaconda2/lib/python2.7/lib-dynload', '/storage/st2/anaconda2/lib/python2.7/site-packages', '/storage/st2/anaconda2/lib/python2.7/site-packages/IPython/extensions', '/public/home/student6/.ipython']
<module 'posixpath' from '/storage/st2/anaconda2/lib/python2.7/posixpath.pyc'>