A more direct analogue of dict.get(key, default) than hasattr is getattr .
val = getattr(obj, 'attr_to_check', default_value)
(Where default_value is optional, throwing an exception without an attribute if not found.)
In your example, you will pass False .
Brian Dec 10 '08 at 14:27 2008-12-10 14:27
source share