Python 中glob模块使用

1.介绍
glob模块用来查找文件目录和文件,常见的两个方法有glob.glob()和glob.iglob(),可以和常用的find功能进行类比,glob支持*?[]这三种通配符

2.三种通配符


*代表0个或多个字符
?代表一个字符
[]匹配指定范围内的字符,如[0-9]匹配数字

3.例子

import glob
filelist=glob.glob('*.py')
print(filelist)
for py in filelist: 
    print(py) 

output:

['eval.py', 'evaluator.py', 'eval_util.py', 'eval_util_test.py', 'exporter.py', 'exporter_test.py', 'export_inference_graph.py', 'generate_tfrecord.py', 'inputs.py', 'inputs_test.py', 'model_hparams.py', 'model_lib.py', 'model_lib_test.py', 'model_main.py', 'model_tpu_main.py', 'Object_detection_image.py', 'Object_detection_video.py', 'Object_detection_webcam.py', 'resizer.py', 'train.py', 'trainer.py', 'trainer_test.py', 'xml_to_csv.py', '__init__.py']
eval.py
evaluator.py
eval_util.py
eval_util_test.py
exporter.py
exporter_test.py
export_inference_graph.py
generate_tfrecord.py
inputs.py
inputs_test.py
model_hparams.py
model_lib.py
model_lib_test.py
model_main.py
model_tpu_main.py
Object_detection_image.py
Object_detection_video.py
Object_detection_webcam.py
resizer.py
train.py
trainer.py
trainer_test.py
xml_to_csv.py
__init__.py

猜你喜欢

转载自www.cnblogs.com/4c4853/p/9782075.html