if not hasattr/if hasattr (attribute) - Python for Integrated Circuits - - An Online Book - |
||||||||
Python for Integrated Circuits http://www.globalsino.com/ICs/ | ||||||||
Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix | ||||||||
================================================================================= ============================================ hasattr(object, name): hasattr() is called by getattr() to check to see if AttributeError is to be raised or not. The hasattr() method returns true if an object has the given named attribute and false if it does not. ============================================ Simple attribute demo: Code: ============================================ Access the attributes in a class: Code: ============================================ Access the local attribute externally: Code: ============================================ Error: Code: ============================================ "Useless" attribute: Code:
|
||||||||
================================================================================= | ||||||||
|
||||||||