Use hasattr() instead of try: except AttributeError

"hasattr()" is the proper Python idiom.