Use hasattr, not getattr in if statements