python中获取当前路径【os模块】

本机windows,文件目录F:\python\ClStudyDemo\osTest.py

 

os.path.realpath(_file_)——返回真实路径

os.path.split()——返回路径的目录和文件名

os.getcwd()——得到当前工作的目录

__file__ 是用来获得模块所在的路径的 

print(os.path.realpath(__file__))
print(os.path.split(os.path.realpath(__file__)))
print(os.getcwd())

 

posted @ 2017-05-24 12:07  dieyaxianju  阅读(30121)  评论(0编辑  收藏  举报