Use hasattr instead of getattr to test iterable