TypeError:NoneType对象不可迭代

以下代码引发此错误:

TypeError:NoneType对象不可迭代

代码有什么问题?

import os 

def wenjian(file):
    for root,dirs,files in os.walk(file):
        for file in files:
            filename = os.path.join(root,file)
            print (filename[-28:])

file = ("C:\\Users\\ZHEN YUAN\\Desktop\\东航try")

Names = wenjian(file)

for i in Names:
    print (i[1])
评论
  • shift
    shift 回复

    Your function wenjian() does not have any return statements, so it will always return None, by default. That's why Names = wenjian(file) assigns the value None to Names, and so you can't iterate over Names with the for loop.