python在指定目录下查找gif文件的方法

yipeiwu_com6年前Python基础

本文实例讲述了python在指定目录下查找gif文件的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/python
# Use the standard find method to look for GIF files.
import sys, find
if len(sys.argv) > 1:
  dirs = sys.argv[1:]
else:
  dirs = [ '.' ]
# Go for it.
for dir in dirs:
  files = find.find('*.gif', dir)
  if files:
    print "For", dir + ':'
    for fn in files:
      print " ", fn
  else:
    print "For", dir + ': None'

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

相关文章

基于Python中单例模式的几种实现方式及优化详解

单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在。当你希望在整个系统中,某个类只能出现一个实例时,单例对象...

用python代码做configure文件

(在lua中通过loadfile, setfenv实现) python当然也可以: cat config.py bar = 10 foo=100 cat python_as_con...

Python中的filter()函数的用法

Python内建的filter()函数用于过滤序列。 和map()类似,filter()也接收一个函数和一个序列。和map()不同的时,filter()把传入的函数依次作用于每个元素,然...

python 捕获shell脚本的输出结果实例

import subprocess output =Popen(["mycmd","myarg"], stdout=PIPE).communicate()[0] import subp...

Python的字典和列表的使用中一些需要注意的地方

Python 中有三个非常好用的数据结构,列表,元组和字典, 元组是不可变的,列表可以保存任意类型的Python对象,并可以随意扩展没有大小限制, 字典是一个key-value的键值映射...