Use hasattr rather than getattr.