1 import os 2 3 print '***獲取當前目錄***' 4 print os.getcwd() 5 print os.path.abspath(os.path.dirname(__file__)) 6 7 print '***獲取上級目錄***' 8 print os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 9 print os.path.abspath(os.path.dirname(os.getcwd())) 10 print os.path.abspath(os.path.join(os.getcwd(), "..")) 11 12 print '***獲取上上級目錄***' 13 print os.path.abspath(os.path.join(os.getcwd(), "../.."))