Use getattr() rather than hasattr() since the latter eats all exceptions, including e.g. KeyboardInterrupt.