推荐学习书目
› 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 · Oct 1, 2019 · 3890 views
    This topic created in 2553 days ago, the information mentioned may be changed or developed.

    image

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

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

    Supplement 1  ·  Oct 1, 2019
    新浪图床怎么看不了了...

    1 replies  •  2019-10-01 10:48:25 +08:00
    ClericPy
        1
    ClericPy  
    OP
       Oct 1, 2019
    问题已解决

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

    结贴
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2637 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 09:22 · PVG 17:22 · LAX 02:22 · JFK 05:22
    ♥ Do have faith in what you're doing.