TypeError: ‘NoneType’ object is not iterable in Python :
It means the value of
You’re calling write_file with arguments like this:
But you haven’t defined ‘foo’ correctly, or you have a typo in your code so that it’s creating a new empty variable and passing it in.
It means that the data variable is passing None (which is type NoneType), its equivalent for nothing. So it can’t be iterable as a list, as you are trying to do.
for row in data:
TypeError: 'NoneType' object is not iterable
Which object is it complaining about? Choice of two,
for row in data, which needs to be iterable? Only
What’s the problem with
data? Its type is
None has type
data is None.
You can verify this in an IDE, or by inserting e.g.
print "data is", repr(data) before the
for statement, and re-running.
Think about what you need to do next: How should “no data” be represented? Do we write an empty file? Do we raise an exception or log a warning or keep silent?