Snippets tagged “hasattr”
2 snippets use this tag.
- How do I check if a variable exists?Python
In Python, you can check if a variable exists by using the globals() or locals() function to check if the variable is in the global or local namespace, respectively.
- How do I check if an object has an attribute?Python
You can use the hasattr function to check if an object has an attribute.