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
bestehen
V2EX  ›  Python

Python 中的 pathlib 怎么用

  •  
  •   bestehen · 2018-09-02 12:06:13 +08:00 · 2177 次点击
    这是一个创建于 2053 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Path('/home/stephen/shenjianlin') PosixPath('/home/stephen/shenjianlin') Path('/home/stephen/shenjianlin').parent PosixPath('/home/stephen') 这里我要的是路径 怎么有 PosixPath 这种东西出来?难道要正则处理?

    matrix273
        1
    matrix273  
       2018-09-02 12:32:02 +08:00 via Android
    str(Path())
    Path().stem
    Path().name
    HelloAmadeus
        2
    HelloAmadeus  
       2018-09-02 12:40:35 +08:00
    因为你在 posix 兼容的系统啊, Path 类是一个接口, posixpath 类是具体实现, 你用就行了
    inframe
        3
    inframe  
       2018-09-02 13:28:10 +08:00 via Android
    读一读 官方的帮助文档
    写得很清楚的
    bestehen
        4
    bestehen  
    OP
       2018-09-02 17:44:52 +08:00
    @matrix273 解决了谢谢
    bestehen
        5
    bestehen  
    OP
       2018-09-02 17:45:18 +08:00
    @inframe 你说的官方文档是那个 piyi 的 homepage 吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1280 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:47 · PVG 01:47 · LAX 10:47 · JFK 13:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.