Reputation: 15
When I am iterating through my variable it gives me an error which I show as below.
Traceback (most recent call last):
File "C:\Users\ZHEN YUAN\Desktop\东航第一步\wen2.py", line 13, in <module>
for i in Names:
TypeError: 'NoneType' object is not iterable
Upvotes: 1
Views: 651
Reputation: 15
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])
PS C:\Users\ZHEN YUAN> & python "c:/Users/ZHEN YUAN/Desktop/东航第一步/wen2.py"
\Desktop\东航try\C2002455.xlsx
Traceback (most recent call last):
File "c:/Users/ZHEN YUAN/Desktop/东航第一步/wen2.py", line 14, in <module>
for i in Names:
TypeError: 'function' object is not iterable
Upvotes: 0
Reputation: 10545
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.
Upvotes: 1