一、獲取當前、上級、上上級目錄
import os
print '***獲取當前目錄***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) print '***獲取上級目錄***' print os.path.abspath(os.path.dirname(os.path.dirname(__file__))) print os.path.abspath(os.path.dirname(os.getcwd())) print os.path.abspath(os.path.join(os.getcwd(), "..")) print '***獲取上上級目錄***' print os.path.abspath(os.path.join(os.getcwd(), "../.."))
來源:https://www.cnblogs.com/dingchuan/p/9381769.html
二:進入目錄
dir=os.getcwd()
os.chdir(dir+"\\data")