use hasattr instead of getattr