V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ClericPy
V2EX  ›  Python

通过 __file__ 和 pathlib 的多个 parent 最多只能向上到 cwd

  •  
  •   ClericPy ·
    ClericPy · 2019-10-01 01:59:29 +08:00 · 2989 次点击
    这是一个创建于 1659 天前的主题,其中的信息可能已经有所发展或是发生改变。

    image

    pathlib.Path(__file__).parent.parent.parent.parent.absolute()

    原本以为会从 __file__ 那个路径一路向上, 看文档也没找到, 这是什么原因呢, 我就是想找个和 cwd 无关, 但是和当前脚本文件绝对相关的绝对路径而已

    第 1 条附言  ·  2019-10-01 09:24:56 +08:00
    新浪图床怎么看不了了...

    1 条回复    2019-10-01 10:48:25 +08:00
    ClericPy
        1
    ClericPy  
    OP
       2019-10-01 10:48:25 +08:00
    问题已解决

    前面 __file__ 的时候就该 absolute() 一次

    结贴
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2640 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:00 · PVG 00:00 · LAX 09:00 · JFK 12:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.