I have a bunch of code that looks similar to this:
try:
auth = page.ItemAttributes.Author
except:
try:
auth = page.ItemAttributes.Creator
except:
auth = None
Is there a nicer way to write out this logic? This makes my code really painful to read. I thought try..finally would work, but I assumed wrong
You can use hasattr to avoid the try/except blocks:
An alternate way to write the above is to use the
elseclause of a Pythonforloop: