Avoid "'NoneType' object is not iterable" Exception in Python 2.7.5