python中关于前后缀操作的详解


本文摘自php中文网,作者黄舟,侵删。


返回后缀名

1

2

3

import os

 

path = 'first_directory/second_directory/file.txt'print os.path.splitext(path)[1]print type(os.path.splitext(path)[1])

1

2

.txt

<type 'str'>

前缀名的bool判断

1

path = 'first_directory/second_directory/file.txt'print path.startswith('fir')

1

True

后缀名的bool判断

1

path = 'first_directory/second_directory/file.txt'print path.endswith('.txt')

1

True

os.path.splitext、.startswith、.startswith 探究

1

2

3

import os

 

path = 'first_directory/second_directory/file.txt'print os.path.splitext(path)print os.path.splitext(path)[1]print type(os.path.splitext(path)[1])printprint path.startswith('fir')print path.startswith('aaa')print type(path.startswith('fir'))printprint path.endswith('.txt')print path.endswith('.aaa')print type(path.endswith('.txt'))

1

2

3

4

5

6

7

8

9

10

11

('first_directory/second_directory/file', '.txt')

.txt

<type 'str'>

 

True

False

<type 'bool'>

 

True

False

<type 'bool'>

以上就是python中关于前后缀操作的详解的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python3中* 和 ** 运算符的用法是什么

Python合法标识符要求是什么

Python中yield什么意思

Python threading模块中的join()方法

Python的编写规范和命名规范的总结

Python opencv设置摄像头分辨率以及各个参数的方法_Python

如何往文件中追加文本

Python自定义对象实现切片功能的介绍(代码示例)

Python中关于前后缀操作的详解

Python使用pandas处理excel的方法

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...