python 过滤出某后缀名文件

以从某文件夹过滤出py文件为例:

法1:

import glob 
import os
os.chdir(“./”)
for file in glob.glob(“*.py”):
    print file

法2:

for file in os.listdir(“./”):
    if file.endswith(“.py”):
        print file    

法3:

for root, dirs, files in os.walk(“./”):
    for file in files:
        if file.endswith(“.py”):
            print os.path.join(root, file)        

方法非原创,文责不负。嘿嘿

posted @ 2018-12-15 09:22  快乐多巴胺  阅读(2475)  评论(0编辑  收藏  举报