[Python-ideas] defaultattrgetter

Nick Coghlan ncoghlan at gmail.com
Thu Dec 22 13:14:12 CET 2011

Once again, please don't get so enamoured of higher order functions
that you miss the obvious solution: *just write a new function that
does exactly what you want*.

"Swiss Army APIs" are not a good thing. Sometimes they're fairly
unavoidable because they're exposing a complex underlying operation
with a lot of moving parts (e.g. subprocess.Popen), but other times
they're useless cruft that is so hard to remember that most people
never bother with them, as just writing the custom function is
significantly easier.

So, for the 3 examples given:

def _x(arg): return getattr(arg, 'x', 0)
def _y(arg): return getattr(arg, 'y', 1)
def _xy(arg): return _x(arg), _y(arg)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list