Is there a nicer way of doing the following:
try:
a.method1()
except AttributeError:
try:
a.method2()
except AttributeError:
try:
If you are using new-style object:
methods = ('method1','method2','method3')
for method in methods:
try:
b = a.__getattribute__(method)
except AttributeError:
continue
else:
b()
break
else:
# re-raise the AttributeError if nothing has worked
raise AttributeError
Of course, if you aren't using a new-style object, you may try __dict__ instead of __getattribute__.
EDIT: This code might prove to be a screaming mess. If __getattribute__ or __dict__ is not found, take a wild guess what kind of error is raised.