简体   繁体   中英

glob.iglob to find all .txt files in all sub-directories yields error

Simple code gives the below error. It's directly from the docs ( https://docs.python.org/3/library/glob.html )

TypeError: iglob() got an unexpected keyword argument 'recursive'

import glob
for filename in glob.iglob('C:\\**\\*txt', recursive=True):
    print filename

看来你正在使用Python 2.7并阅读Python 3.5文档。

The recursive parameter has been added in python 3.5, which means version 3.4.3 also has that problem.

If you don't want to upgrade your python version, you can use glob2 , which supports recursive calls ( ** ) by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM