<div dir="ltr"><div><div>Hi Vincent,<br><br></div>Your idea is interesting but we are worried that there are not enough real use cases where it would be useful. Have you encountered situations yourself where this would make a difference? I am asking not for clarifying examples (you already provided one and from that it's perfectly clear to me what you are proposing) but for real-world code that would benefit from this addition to the itemgetter API.<br><br></div>--Guido<br><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 2, 2018 at 1:08 AM, Vincent Maillol <span dir="ltr"><<a href="mailto:vincent.maillol@gmail.com" target="_blank">vincent.maillol@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everybody,<br>
<br>
Our PEP idea would be to purpose to add a global default value for<br>
itemgeet and attrgetter method.<br>
<br>
This was inspired from bug 14384 (<a href="https://bugs.python.org/issue14384" rel="noreferrer" target="_blank">https://bugs.python.org/<wbr>issue14384</a>);<br>
opened by Miki TEBEKA.<br>
<br>
For example, we could do:<br>
<br>
p1 = {'x': 43; 'y': 55}<br>
x, y, z = itemgetter('x', 'y', 'z', default=0)(values)<br>
print(x, y, z)<br>
43, 55, 0<br>
<br>
instead of:<br>
<br>
values = {'x': 43; 'y': 55}<br>
x = values.get('x', 0)<br>
y = values.get('y', 0)<br>
z = values.get('z', 0)<br>
print(x, y, z)<br>
43, 55, 0<br>
<br>
The goal is to have have concise code and improve consistency with<br>
getattr, attrgetter and itemgetter<br>
<br>
What are you thinking about this?<br>
<span class="HOEnZb"><font color="#888888"><br>
MAILLOL Vincent<br>
GALODE Alexandre<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div></div></div></div>