Code: for row in data:
Error message: TypeError: 'NoneType' object is not iterable
Which object is it complaining about? Choice of two, row and data.
In for row in data, which needs to be iterable? Only data.
What's the problem with data? Its type is NoneType. Only None has type NoneType. So 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?