zoukankan      html  css  js  c++  java
  • Python os.path模块

    1、os.path.splitext(path)  #返回一个元祖(路经,扩展名)

    例如:

    >>> os.path.splitext('/home/biotrainee/first/test.txt')
    ('/home/biotrainee/first/test', '.txt')

    而os.path.split(path) 是返回(路经,文件名.扩张名)

    >>> os.path.split('/home/biotrainee/first/test.txt')
    ('/home/biotrainee/first', 'test.txt')

    2、os.path.dirname(path) 返回文件路经的目录,也就是os.path.split(path)第一个元素,如:

    >>> os.path.dirname('/home/biotrainee/first/test.txt')
    '/home/biotrainee/first'

    3、os.path.basename(path)返回path的最后文件名,也就是os.path.split(path)第二个元素,如:

    >>> os.path.basename('/home/biotrainee/first/test.txt')
    'test.txt'

    4、os.path.exists(path)   如果path存在,返回True;如果path不存在,返回False。如:

    >>> os.path.exists('/home/biotrainee/first/test.txt')
    False
    >>> os.path.exists('/home/')
    True

    5、os.path.isabs(path)   如果path是绝对路径,返回True。如:

    >>> os.path.isabs('/home/biotrainee/first/test.txt')
    True
    >>> os.path.isabs('../biotrainee/first/test.txt')
    False

    等等等等,未完待续。。。

  • 相关阅读:
    BZOJ 3144 [Hnoi2013]切糕
    一场比赛:20170707
    BZOJ 2815 [ZJOI2012]灾难
    BZOJ 1088 [SCOI2005]扫雷Mine
    BZOJ 1052 [HAOI2007]覆盖问题
    BZOJ 3505 [Cqoi2014]数三角形
    BZOJ 2957 楼房重建
    BZOJ 2654 tree
    丁酉年六月十一ACM模拟赛
    BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑
  • 原文地址:https://www.cnblogs.com/nklzj/p/6890725.html
Copyright © 2011-2022 走看看