获取当前路径

 

import os
print os.path.abspath(__file__) #返回脚本名称(包含全路径),如C:\Django\workplace\sf\sinfors\tests5.py
print os.path.dirname(os.path.abspath(__file__)) #返回脚本所在目录,如C:\Django\workplace\sf\sinfors
print os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #返回脚本所在目录的父目录,如C:\Django\workplace\sf

 

import os
logf = os.path.join(os.getcwd(),'log.log')
fw = open(logf,'a')
fw.write('aa')
fw.close()

 

posted on 2016-03-15 15:53  momingliu11  阅读(225)  评论(0编辑  收藏  举报