Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试解析这个目录,我想查看除三个特定名称之外的所有 txt 文件。使用我编写的代码,我可以获得所有目录中的所有文本文件。
for root,dirnames,filenames in os.walk('D:/datast12'): for filename in fnmatch.filter(filenames, '*.txt'): matches.append([root,filenames])
有谁知道我该怎么办?
files_to_ignore = ('abc.txt', 'foo.txt', 'bar.txt') for root,dirnames,filenames in os.walk('D:/datast12'): for filename in fnmatch.filter(filenames, '*.txt'): if filename in files_to_ignore: continue matches.append([root,filenames])