glob模块是最简单的模块之一,内容非常少。用它可以查找符合特定规则的文件路径名。跟使用windows下的文件搜索差不多。查找文件只用到三个匹配符:”*”, “?”, “[]”。”*”匹配0个或多个字符;”?”匹配单个字符;”[]”匹配指定范围内的字符,如:[0-9]匹配数字。
glob.glob
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
glob.glob
返回所有匹配的文件路径列表。它只有一个参数pathname,定义了文件路径匹配规则,这里可以是绝对路径,也可以是相对路径。下面是使用glob.glob的例子:
# File: builtin-glob-example-1.py
import glob
for module_file in glob.glob("*-plugin.py"):
print(module_file)
print('*'*50)
for module_file in glob.glob("*.py"):
print(module_file)
输出如下:
==== RESTART: D:/work/csdn/python_Game1/example/builtin-glob-example-1.py ====
example-plugin.py
**************************************************
builtin-apply-example-1.py
builtin-apply-example-2.py
builtin-glob-example-1.py
builtin-import-example-1.py
example-plugin.py
>>>