<p><br>
On Dec 22, 2011 9:56 AM, "John O&apos;Connor" <<a href="mailto:jxo6948@rit.edu">jxo6948@rit.edu</a>> wrote:<br>
><br>
> > I think the idea is that you ask for an attribute, which (in the less common<br>
> > cases) happens to be a multi-step lookup, and if the attribute is not found,<br>
> > you want it to return a default value *for the attribute you requested*,<br>
> > i.e. not a different value for any of the intermediate attributes, only a<br>
> > specific value that corresponds to the last attribute in the lookup chain.<br>
> > In the 99.9% case, that will be something like None or a "keep going, I<br>
> > don't care" value, not something that depends on the lookup path in any way.<br>
> ><br>
> > I don't think the 0.1% case where you want more than that is worth a<br>
> > substantially more complicated API.<br>
> ><br>
><br>
> I could settle for the default= but I think it is too simple and thus<br>
> incomplete. I think it is extreme to say that one default argument<br>
> covers 99.9% use case. I do think you are right about the ignored path<br>
> but that path may use more than one condition.<br>
><br>
> _xy = defaultattrgetter(('x', True), ('y', False))<br>
> x, y = _xy(foo)<br>
> # usually do x unless told otherwise<br>
> if x: ...<br>
> # usually dont do y<br>
> if y: ...<br>
><br>
><br>
> I guess one alternative could be:<br>
> _xy = attrgetter('x', 'y', defaults={'x': True, 'y': False})<br>
><br>
> but that just looks like DRY without the D.</p>
<p>You could have attrgetter('x', 'y', defaults=(True, False)) to put the D back in.</p>
<p>Arnaud<br>
</p>