Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python class optional attributes

You can use hasattr and getattr.

For example:

hasattr(foo, 'bar')
would return True if foo has an attribute named bar, otherwise False and

getattr(foo, 'bar', 'quux')
would return foo.bar if it exists, otherwise defaults to quux.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #class #optional #attributes
ADD COMMENT
Topic
Name
2+6 =