Programming Tip -How to handle exception inside a Python for loop?