python获取当前路径和上一级路径

"""获取当前目录"""
print(os.getcwd())
print(os.path.abspath(os.path.dirname(__file__)))
"""获取上一级目录"""
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(os.path.abspath(os.path.join(os.getcwd(),"../..")))


对应输出结果、

D:\My\cloud_ui\util
D:\My\cloud_ui\util
D:\My\cloud_ui
D:\My\cloud_ui
D:\My\cloud_ui
D:\My

posted @ 2020-11-14 22:14  行走的小z  阅读(6734)  评论(0编辑  收藏  举报