logo
  • 教程列表
  • SO官方文檔
  • Oskpth
    • 加入路徑
    • 路徑元件操作
    • 相對路徑的絕對路徑
    • 獲取父目錄
    • 如果給定路徑存在
    • 檢查給定路徑是否是目錄檔案符號連結掛載點等
  1. StackOverflow 文件
  2. Python Language 教程
  3. Oskpth
  4. 路徑元件操作

路徑元件操作

Created: November-22, 2018

要從路徑中拆分一個元件:

>>> p = os.path.join(os.getcwd(), 'foo.txt')
>>> p
'/Users/csaftoiu/tmp/foo.txt'
>>> os.path.dirname(p)
'/Users/csaftoiu/tmp'
>>> os.path.basename(p)
'foo.txt'
>>> os.path.split(os.getcwd())
('/Users/csaftoiu/tmp', 'foo.txt')
>>> os.path.splitext(os.path.basename(p))
('foo', '.txt')
  • 相對路徑的絕對路徑
  • 加入路徑

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明