上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖

python获取上一级目录

[复制链接]
  • TA的每日心情
    奋斗
    前天 08:49
  • 签到天数: 426 天

    [LV.9]以坛为家II

    148

    主题

    423

    回帖

    1141

    积分

    版主

    积分
    1141

    油中2周年生态建设者

    发表于 2020-12-21 14:03:15 | 显示全部楼层 | 阅读模式

    import os

    1. print('获取当前目录')
    2. print(os.getcwd())
    3. print(os.path.abspath(os.path.dirname(file)))
    4. print('获取上级目录')
    5. print(os.path.abspath(os.path.dirname(os.path.dirname(file))))
    6. print(os.path.abspath(os.path.dirname(os.getcwd())))
    7. print(os.path.abspath(os.path.join(os.getcwd(), "..")))
    8. print('获取上上级目录')
    9. print(os.path.abspath(os.path.dirname(os.path.dirname(file))))
    10. print(os.path.abspath(os.path.join(os.getcwd(), "../..")))

    原文地址:https://blog.csdn.net/qq_43178297/article/details/88053836

    已有1人评分贡献 理由
    李恒道 + 1 赞一个!

    查看全部评分 总评分:贡献 +1 

    I don't hate programming but the fucking world.

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表