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

2021-03-17 12:25

阅读:371

标签:getc   当前目录   路径   print   bsp   获取   目录   dir   dirname   

"""获取当前目录"""
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

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

标签:getc   当前目录   路径   print   bsp   获取   目录   dir   dirname   

原文地址:https://www.cnblogs.com/xiaozeng6/p/13974989.html


评论


亲,登录后才可以留言!