Re: Incompatible change discussion: Pretty printing of ordered dict.
Steve Holden <[email protected]> Fri, 4 Aug 2017 16:21:05 +0100
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============6937393106003419176== Content-Type: multipart/alternative; boundary=Apple-Mail-7F3C548E-6DDC-496B-80CE-7334A6B20B48 Content-Transfer-Encoding: 7bit --Apple-Mail-7F3C548E-6DDC-496B-80CE-7334A6B20B48 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable It's always difficult to change a long-established behaviour. I'd prefer tha= t dict printing stayed as it is - I haven't seen many complaints so far, an= d as has been pointed out the key ordering is available if required. S Sent from my iPhone > On 4 Aug 2017, at 15:36, Wes Turner <[email protected]> wrote: >=20 > ```python > repr(dict) >=20 > import pprint > pprint.pprint(dict) > print(pprint.pformat(dict) > ``` >=20 >> On Friday, August 4, 2017, MinRK <[email protected]> wrote: >> I'm pretty strongly in favor of keeping the sorting in our default pretty= -printing. It's extremely valuable for interacting with dictionaries to have= consistent, predictable display. There are plenty of ways to illustrate dic= t ordering, such as by iterating through the dict , e.g. `list(dict)`. >>=20 >> -Min >>=20 >>> On Thu, Aug 3, 2017 at 6:38 PM, Carl Smith <[email protected]> wrote:= >>> I'm with Thomas. >>>=20 >>>=20 >>>> On Wed, 2 Aug 2017 22:30 Wes Turner, <[email protected]> wrote: >>>> Maybe a SORT_DICT_KEYS bool configuration setting? Really practically o= nly in order to teach: >>>>=20 >>>> - dict >>>> - https://docs.python.org/3/tutorial/datastructures.html#dictionaries= >>>> - PYTHONHASHSEED / -R >>>> - https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED >>>> - https://docs.python.org/3/using/cmdline.html#cmdoption-R >>>> - collections.OrderedDict (is backwards compatible) >>>> - https://docs.python.org/3/library/collections.html#ordereddict-obje= cts >>>>=20 >>>>=20 >>>>=20 >>>>> On Wednesday, August 2, 2017, Matthias Bussonnier <bussonniermatthias@= gmail.com> wrote: >>>>> Hi all, >>>>>=20 >>>>> As you may or may not be aware, with Python 3.6 the dictionary are >>>>> ordered by default. It is technically an implementation detail, though= >>>>> some people would love for it not to. >>>>>=20 >>>>> Regardless, IPython has for a long time pretty-printed the dictionary >>>>> with _sorted_ keys, this thus prevent to teach python and show that >>>>> dictionaries maintain order. Thus there is the question of wether we >>>>> should disable sorting keys while pretty-printing. >>>>>=20 >>>>> https://github.com/ipython/ipython/issues/10110 >>>>>=20 >>>>> This seem like a minor change, but I'd like to know if some of you are= >>>>> _relying_ on the ordering of dict when they are printed, or have >>>>> compelling arguments against (or for) removing sorting of the keys >>>>> before pretty_printing. >>>>>=20 >>>>> If you care about the above subject, please have your voice heard in >>>>> above issue. >>>>>=20 >>>>> Thanks, >>>>> -- >>>>> Matthias >>>>> _______________________________________________ >>>>> IPython-dev mailing list >>>>> [email protected] >>>>> https://mail.python.org/mailman/listinfo/ipython-dev >>>> _______________________________________________ >>>> IPython-dev mailing list >>>> [email protected] >>>> https://mail.python.org/mailman/listinfo/ipython-dev >>>=20 >>> _______________________________________________ >>> IPython-dev mailing list >>> [email protected] >>> https://mail.python.org/mailman/listinfo/ipython-dev >>>=20 >>=20 > _______________________________________________ > IPython-dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/ipython-dev --Apple-Mail-7F3C548E-6DDC-496B-80CE-7334A6B20B48 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head><body dir=3D"auto"><div>It's always difficult to change a long= -established behaviour. I'd prefer that dict printing stayed as it is -= I haven't seen many complaints so far, and as has been pointed out the key o= rdering is available if required. S<br><br>Sent from my iPhone</div><d= iv><br>On 4 Aug 2017, at 15:36, Wes Turner <<a href=3D"mailto:wes.turner@= gmail.com">[email protected]</a>> wrote:<br><br></div><blockquote type= =3D"cite"><div><div>```python</div>repr(dict)<div><br></div><div>import ppri= nt</div><div>pprint.pprint(dict)</div><div>print(pprint.pformat(dict)</div><= div>```<br><br>On Friday, August 4, 2017, MinRK <<a href=3D"mailto:benjam= [email protected]">[email protected]</a>> wrote:<br><blockquote class=3D"= gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l= eft:1ex"><div dir=3D"ltr">I'm pretty strongly in favor of keeping the sortin= g in our default pretty-printing. It's extremely valuable for interacting wi= th dictionaries to have consistent, predictable display. There are plenty of= ways to illustrate dict ordering, such as by iterating through the dict , e= .g. `list(dict)`.<div><br></div><div>-Min</div></div><div class=3D"gmail_ext= ra"><br><div class=3D"gmail_quote">On Thu, Aug 3, 2017 at 6:38 PM, Carl Smit= h <span dir=3D"ltr"><<a href=3D"javascript:_e(%7B%7D,'cvml','carl.input@g= mail.com');" target=3D"_blank">[email protected]</a>></span> wrote:<br= ><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><p dir=3D"ltr">I'm with Thomas. </p><div><div= > <br><div class=3D"gmail_quote"><div dir=3D"ltr">On Wed, 2 Aug 2017 22:30 Wes= Turner, <<a href=3D"javascript:_e(%7B%7D,'cvml','[email protected]');= " target=3D"_blank">[email protected]</a>> wrote:<br></div><blockquote= class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid= ;padding-left:1ex">Maybe a SORT_DICT_KEYS bool configuration setting? Really= practically only in order to teach:<div><br></div><div>- dict</div><div>&nb= sp; - <a href=3D"https://docs.python.org/3/tutorial/datastructures.html= #dictionaries" target=3D"_blank">https://docs.python.org/3/tu<wbr>torial/dat= astructures.html#dic<wbr>tionaries</a></div><div>- <span style=3D"color= :rgb(34,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,sans-serif;fon= t-size:14px">PYTHONHASHSEED / -R</span></div><div><span style=3D"color:rgb(3= 4,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,sans-serif;font-size= :14px"> - </span><font color=3D"#222222" face=3D"Roboto-Regular, H= elveticaNeue, Arial, sans-serif"><span style=3D"font-size:14px"><a href=3D"h= ttps://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED" target=3D= "_blank">https://docs.python.org/3/us<wbr>ing/cmdline.html#envvar-PYTHON<wbr= >HASHSEED</a></span></font></div><div><font color=3D"#222222" face=3D"Roboto= -Regular, HelveticaNeue, Arial, sans-serif"><span style=3D"font-size:14px">&= nbsp; - <a href=3D"https://docs.python.org/3/using/cmdline.html#cmdoption-R"= target=3D"_blank">https://docs.python.org/3/usin<wbr>g/cmdline.html#cmdopti= on-R</a></span></font></div><div><font color=3D"#222222" face=3D"Roboto-Regu= lar, HelveticaNeue, Arial, sans-serif"><span style=3D"font-size:14px">- coll= ections.OrderedDict (is backwards compatible)</span></font></div><div><span s= tyle=3D"color:rgb(34,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,s= ans-serif;font-size:14px"> - <a href=3D"https://docs.python.org/3= /library/collections.html#ordereddict-objects" target=3D"_blank">https://doc= s.python.org/3/li<wbr>brary/collections.html#ordered<wbr>dict-objects</a></s= pan></div><div><font color=3D"#222222" face=3D"Roboto-Regular, HelveticaNeue= , Arial, sans-serif"><span style=3D"font-size:14px"><br></span></font></div>= <div><font color=3D"#222222" face=3D"Roboto-Regular, HelveticaNeue, Arial, s= ans-serif"><span style=3D"font-size:14px"><br></span></font><br>On Wednesday= , August 2, 2017, Matthias Bussonnier <<a href=3D"javascript:_e(%7B%7D,'c= vml','[email protected]');" target=3D"_blank">bussonniermatthias@= gmail.com</a>> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margi= n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br> <br> As you may or may not be aware, with Python 3.6 the dictionary are<br> ordered by default. It is technically an implementation detail, though<br> some people would love for it not to.<br> <br> Regardless, IPython has for a long time pretty-printed the dictionary<br> with _sorted_ keys, this thus prevent to teach python and show that<br> dictionaries maintain order. Thus there is the question of wether we<br> should disable sorting keys while pretty-printing.<br> <br> <a href=3D"https://github.com/ipython/ipython/issues/10110" target=3D"_blank= ">https://github.com/ipython/ipy<wbr>thon/issues/10110</a><br> <br> This seem like a minor change, but I'd like to know if some of you are<br> _relying_ on the ordering of dict when they are printed, or have<br> compelling arguments against (or for) removing sorting of the keys<br> before pretty_printing.<br> <br> If you care about the above subject, please have your voice heard in<br> above issue.<br> <br> Thanks,<br> --<br> Matthias<br> ______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a>[email protected]</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" target=3D"_= blank">https://mail.python.org/mailma<wbr>n/listinfo/ipython-dev</a><br> </blockquote></div> ______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a href=3D"javascript:_e(%7B%7D,'cvml','[email protected]');" target=3D= "_blank">[email protected]</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nore= ferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ipyt= hon-dev</a><br> </blockquote></div> </div></div><br>______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a href=3D"javascript:_e(%7B%7D,'cvml','[email protected]');" target=3D= "_blank">[email protected]</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nore= ferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ipyt= hon-dev</a><br> <br></blockquote></div><br></div> </blockquote></div> </div></blockquote><blockquote type=3D"cite"><div><span>____________________= ___________________________</span><br><span>IPython-dev mailing list</span><= br><span><a href=3D"mailto:[email protected]">[email protected]</a= ></span><br><span><a href=3D"https://mail.python.org/mailman/listinfo/ipytho= n-dev">https://mail.python.org/mailman/listinfo/ipython-dev</a></span><br></= div></blockquote></body></html>= --Apple-Mail-7F3C548E-6DDC-496B-80CE-7334A6B20B48-- --===============6937393106003419176== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ IPython-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/ipython-dev --===============6937393106003419176==--