python查找目录下指定扩展名的文件实例

yipeiwu_com6年前Python基础

本文实例讲述了python查找目录下指定扩展名的文件。分享给大家供大家参考。具体如下:

这里使用python查找当前目录下的扩展名为.txt的文件

import os
items = os.listdir(".")
newlist = []
for names in items:
  if names.endswith(".txt"):
    newlist.append(names)
print newlist

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python中用于计算对数的log()方法

 log()方法返回x的自然对数,对于x>0。 语法 以下是log()方法的语法: import math math.log( x ) 注意:此函数是无法直接...

十条建议帮你提高Python编程效率

十条建议帮你提高Python编程效率

程序员的时间很宝贵,Python这门语言虽然足够简单、优雅,但并不是说你使用Python编程,效率就一定会高。要想节省时间、提高效率,还是需要注意很多地方的。 今天就与大家分享资深Pyt...

python基于queue和threading实现多线程下载实例

本文实例讲述了python基于queue和threading实现多线程下载的方法,分享给大家供大家参考。具体方法如下: 主代码如下: #download worker qu...

python简单实现旋转图片的方法

本文实例讲述了python简单实现旋转图片的方法。分享给大家供大家参考。具体实现方法如下: # rotate an image counter-clockwise using the...

python 将字符串转换成字典dict

复制代码 代码如下:JSON到字典转化:dictinfo = simplejson.loads(json_str) 输出dict类型 字典到JSON转化:jsoninfo = simpl...