python 获取当前目录,上级目录,上上级目录

'''
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(), "../..")))
'''

你可能感兴趣的:(python 获取当前目录,上级目录,上上级目录)