Every line of 'python hasattr' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
64 def _hasattr(obj, attr_name): 65 # If possible, avoid retrieving the attribute as the object might run some 66 # lazy computation in it. 67 if attr_name in dir(obj): 68 return True 69 try: 70 getattr(obj, attr_name) 71 except AttributeError: 72 return False 73 else: 74 return True