You can use hasattr to avoid try / except blocks:
auth = None for attrname in ['Author', 'Creator']: if hasattr(page.ItemAttributes, attrname): auth = getattr(page.ItemAttributes, attrname) break
An alternative way to write above is to use the else clause of the Python for loop:
for attrname in ['Author', 'Creator']: if hasattr(page.ItemAttributes, attrname): auth = getattr(page.ItemAttributes, attrname) break else: auth = None
Mark byers
source share