The Strategy Pattern is used for these kinds of problems. In python, I would probably start out with simply using function pointers. You have a lot of options of how attack this in Python but here's one possible answer:
def myFunc(a, b):
try:
modeFunc = locals()[a]
except:
modeFunc = standard
return modeFunc(b)
and then you'd have something like this:
def standard(b)
print "do for any mode"
print "do some more stuff for any mode"
def mode1(b)
print "special mode stuff"
print "do for any mode"
print "special mode stuff"
print "do some more stuff for any mode"
The obvious issue here is that you have common code interspersed throughout. If this is really common and has to happen across the board you might want to go with the Template Pattern as pointed out by gnat. It's basically the Strategy pattern but perhaps with more structure.
It's really hard to say whether to stick to the simple approach (and accept some redundancy) or go with something more structured. Personally, I'd choose the one that required less work which tends to be the simple one and then refactor if you end up with a maintenance.
Another option is to do both. That is, use function pointers and sometimes they might point to a template pattern object or other times they just point to a simple method. This is a good option if you have common logic with exceptions. That is, if you have conditions like this:
if a != "mode6":
print "do some more stuff for any mode except mode 6"