首页 > 编程语言 > 详细

Python - 多次检查后缀名(endwith)

时间:2015-07-26 09:48:44      阅读:345      评论:0      收藏:0      [点我收藏+]

在通过后缀名查找类型文件的时候, 多次使用endwith, 使用元组(tuple), 简化操作.
此类方式, 也可以应用于if语句多次相似检测.


代码

# 列出文件夹内所有代码
def list_dictionary_codes(root_dir):
    paths_list = []
    for parent, dirNames, fileNames in os.walk(root_dir):
        for name in fileNames:
            ext = [‘.h‘, ‘.m‘, ‘.xib‘, ‘.json‘, ‘.c‘, ‘.cpp‘, ‘.mm‘, ‘.md‘]
            if name.endswith(tuple(ext)):
                paths_list.append(os.path.join(parent, name))
    return paths_list

版权声明:本文为博主原创文章,未经博主允许不得转载。

Python - 多次检查后缀名(endwith)

原文:http://blog.csdn.net/caroline_wendy/article/details/47065161

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!