定义区别
- os.path 主要是用于对系统路径文件的操作。
- sys.path 主要是对Python解释器的系统环境参数的操作(动态的改变Python解释器搜索路径)。
验证
>>> import os,sys
>>> print(os.path)
<module 'posixpath' from '/usr/lib64/python2.7/posixpath.pyc'>
>>> print(sys.path)
[ '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']
其他
获取当前目录
test.py
# coding:utf-8
import sys,os
real_dir = os.path.realpath(__file__)
print(real_dir)
/// /home/code/test/test.py
cur_dir = os.path.dirname(os.path.realpath(__file__))
print(cur_dir)
/// /home/code/test
标签:Python,python2.7,sys,usr,path,lib64,os
From: https://www.cnblogs.com/xiaohaigegede/p/16940936.html