1. 程式人生 > >python中os.path常用模組

python中os.path常用模組

os.path.sep:路徑分隔符 linux下就用這個了’/’ os.path.altsep: 根目錄 os.path.curdir:當前目錄 os.path.pardir:父目錄 os.path.abspath(path):絕對路徑 os.path.join(): 常用來連結路徑 os.path.split(path): 把path分為目錄和檔案兩個部分,以列表返回
  1. [GCC 4.4.5] on linux2
  2. Type "help","copyright","credits" or"license" for more information.
  3. >>>import os
  4. >>> help('os.path.sep')
  5. >>>print os.path.sep
  6. /
  7. >>>print os.path.altsep
  8. None
  9. >>>print os.path.curdir
  10. .
  11. >>>print os.path.abspath('/root')
  12. /root
  13. >>>print
    os.path.abspath('/root/pp')
  14. /root/pp
  15. >>>print os.path.abspath('/root/pp/f.c')
  16. /root/pp/f.c
  17. >>>print os.path.split('/root/pp/f.c')
  18. ('/root/pp','f.c')
  19. >>>