Use getattr instead of try-catch block