這段代碼有什麼問題?我想在文件夾中找到指定的文件。 Thansk爲你提供幫助。Python,找到文件夾中的指定文件
import os, fnmatch
def find(root, mask): //Error
files_list = os.listdir(os.path.abspath(root))
for filename in fnmatch.filter(files_list, mask):
yield filename
def test():
res = find ('D:\\Sample\\', 'hallo.txt')
test()
錯誤:
Error: Traceback (most recent call last): def find(root, mask): NoneType
'os.dir'應該是什麼? –
那麼你有什麼錯誤,或者你的代碼有什麼問題? – sth
@sth:對不起,我沒有寫錯誤代碼:-) – abcdef