获取当前路径
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()