There's one thing that newer python programmers seem to have difficulty coming to terms with: duck typing. Duck typing isn't quite the same thing as dynamic typing. For example, suppose I have an object x that I want to do something with. Many developers coming from statically typed languages will be tempted to do this:
if isinstance(x, someclass):
x.somemethod()
else:
print "an error has occurred!"
The problem with this code is that Python has no concept of interfaces. So if you want to create an object that can pose as an instance of someclass without directly inheriting it, you're SOL. You can also do this:
if hasattr(x, somemethod):
x.somemethod()
else:
print "an error has occurred!"
But this can be tricky because python's dynamic typing can allow you to call a method even if it's not explicitly set to an attribute (see getattribute for more info).
There's an alternative way though:
try:
x.somemethod()
except AttributeError:
print "an error has occurred!"
Though this use of exceptions will probably horrify the .net programmers out there, this is the most pythonic way to do the code. It also just so happens to be the only way that you can be 100% sure that x has or doesn't have a somemethod method.