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


	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:Mycloud_uiutil
D:Mycloud_uiutil
D:Mycloud_ui
D:Mycloud_ui
D:Mycloud_ui
D:My

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

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

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python获取当前路径和上一级路径