以下代码引发此错误:
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])
Your function
wenjian()
does not have anyreturn
statements, so it will always returnNone
, by default. That's whyNames = wenjian(file)
assigns the valueNone
toNames
, and so you can't iterate overNames
with the for loop.