Re: display of dicts?
Nathan Goldbaum <[email protected]> Mon, 18 Dec 2017 21:04:31 -0600
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CAJXewOkjmob=V_6rN3sT2qnsqvOSE7ZNvSb6rQfeBDyBMkGxuA@mail.gmail.com> |
--===============8514200170101176997== Content-Type: multipart/alternative; boundary="f403043a0bb80e7a730560a8bb25" --f403043a0bb80e7a730560a8bb25 Content-Type: text/plain; charset="UTF-8" Nope, I believe it's this: https://github.com/ipython/ipython/blob/dc9d1c679424589480bb83af64aa5ee21031d311/IPython/lib/pretty.py On Mon, Dec 18, 2017 at 7:56 PM, Chris Barker <[email protected]> wrote: > Thanks Nathan, > > And to confirm, this is the stdlib's pprint module, yes? > > (which does seem to show the same behavior) > > -CHB > > > > On Mon, Dec 18, 2017 at 5:40 PM, Nathan Goldbaum <[email protected]> > wrote: > >> IPython does use pretty-printing by default. You can control it with the >> %pprint magic, in your IPython configuration, with the >> PlainTextFormatter.pprint option, or with the --pprint command line >> argument when starting IPython. >> >> http://ipython.readthedocs.io/en/stable/config/options/termi >> nal.html#configtrait-PlainTextFormatter.pprint >> >> >> >> On Mon, Dec 18, 2017 at 7:08 PM, Chris Barker <[email protected]> >> wrote: >> >>> As Guido has just declared that dicts will now officially preserve order: >>> >>> https://mail.python.org/pipermail/python-dev/2017-December/151283.html >>> >>> I was playing around them in py3.6 ipython, and found some (to me) odd >>> behavior: >>> >>> In [1]: d = {'one':1, 'two':2, 'three':3} >>> >>> In [2]: d >>> Out[2]: {'one': 1, 'three': 3, 'two': 2} >>> >>> Hmm -- order does not appear to be preserved. >>> >>> But then: >>> >>> In [3]: str(d) >>> Out[3]: "{'one': 1, 'two': 2, 'three': 3}" >>> >>> In [4]: repr(d) >>> Out[4]: "{'one': 1, 'two': 2, 'three': 3}" >>> >>> In [5]: d.values() >>> Out[5]: dict_values([1, 2, 3]) >>> >>> In [6]: d.keys() >>> Out[6]: dict_keys(['one', 'two', 'three']) >>> >>> In [7]: d.items() >>> Out[7]: dict_items([('one', 1), ('two', 2), ('three', 3)]) >>> >>> Order IS preserved. >>> >>> So presumably iPython is calling sorted() or some such when displaying a >>> dict. >>> >>> Is that that case? Is that documented anywhere?? I can't find it. >>> >>> And with Python >= 3.6, dict order is preserved, so it would probably be >>> better to NOT mess with dict order when displaying them in iPython. >>> >>> SIDE NOTE: >>> >>> I had a bit of trouble finding this mailing list -- google still points >>> to the old ones on scipy.org. -- maybe we can put a note on the home >>> page of those lists that they are been moved?? >>> >>> (I only noticed, 'cause the archives of those stop last March) >>> >>> -Chris >>> >>> >>> >>> >>> >>> -- >>> >>> Christopher Barker, Ph.D. >>> Oceanographer >>> >>> Emergency Response Division >>> NOAA/NOS/OR&R (206) 526-6959 voice >>> 7600 Sand Point Way NE (206) 526-6329 fax >>> Seattle, WA 98115 (206) 526-6317 main reception >>> >>> [email protected] >>> >>> _______________________________________________ >>> 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 >> >> > > > -- > > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > [email protected] > > _______________________________________________ > IPython-dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/ipython-dev > > --f403043a0bb80e7a730560a8bb25 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Nope, I believe it's this: <a href=3D"https://github.c= om/ipython/ipython/blob/dc9d1c679424589480bb83af64aa5ee21031d311/IPython/li= b/pretty.py">https://github.com/ipython/ipython/blob/dc9d1c679424589480bb83= af64aa5ee21031d311/IPython/lib/pretty.py</a><br></div><div class=3D"gmail_e= xtra"><br><div class=3D"gmail_quote">On Mon, Dec 18, 2017 at 7:56 PM, Chris= Barker <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a>></span> wrote:<br><blockquote cl= ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p= adding-left:1ex"><div dir=3D"ltr"><div><div><div>Thanks Nathan,<br><br></di= v>And to confirm, this is the stdlib's pprint module, yes?<br><br></div= >(which does seem to show the same behavior)<br><br></div>-CHB<br><br><div>= <div><br></div></div></div><div class=3D"HOEnZb"><div class=3D"h5"><div cla= ss=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mon, Dec 18, 2017 at 5= :40 PM, Nathan Goldbaum <span dir=3D"ltr"><<a href=3D"mailto:nathan12343= @gmail.com" target=3D"_blank">[email protected]</a>></span> wrote:<b= r><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:= 1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">IPython does use pretty-p= rinting by default. You can control it with the %pprint magic, in your IPyt= hon configuration, with the PlainTextFormatter.pprint option, or with the -= -pprint command line argument when starting IPython.<br><br><a href=3D"http= ://ipython.readthedocs.io/en/stable/config/options/terminal.html#configtrai= t-PlainTextFormatter.pprint" target=3D"_blank">http://ipython.readthedocs.i= o/<wbr>en/stable/config/options/termi<wbr>nal.html#configtrait-PlainText<wb= r>Formatter.pprint</a><br><br><br></div><div class=3D"gmail_extra"><br><div= class=3D"gmail_quote"><div><div class=3D"m_-6421650856597578850h5">On Mon,= Dec 18, 2017 at 7:08 PM, Chris Barker <span dir=3D"ltr"><<a href=3D"mai= lto:[email protected]" target=3D"_blank">[email protected]</a>><= /span> wrote:<br></div></div><blockquote class=3D"gmail_quote" style=3D"mar= gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class= =3D"m_-6421650856597578850h5"><div dir=3D"ltr"><div>As Guido has just decla= red that dicts will now officially preserve order:<br clear=3D"all"><div><b= r><a href=3D"https://mail.python.org/pipermail/python-dev/2017-December/151= 283.html" target=3D"_blank">https://mail.python.org/piperm<wbr>ail/python-d= ev/2017-December/1<wbr>51283.html</a><br><br></div><div>I was playing aroun= d=C2=A0 them in py3.6 ipython, and found some (to me) odd behavior:<br><br>= <span style=3D"font-family:monospace,monospace">In [1]: d =3D {'one'= ;:1, 'two':2, 'three':3}<br><br>In [2]: d<br>Out[2]: {'= one': 1, 'three': 3, 'two': 2}<br><br></span></div>Hmm = -- order does not appear to be preserved.<br><br></div>But then:<span style= =3D"font-family:monospace,monospace"></span><br><div><span style=3D"font-fa= mily:monospace,monospace"></span><div><span style=3D"font-family:monospace,= monospace"><br>In [3]: str(d)<br>Out[3]: "{'one': 1, 'two&= #39;: 2, 'three': 3}"<br><br>In [4]: repr(d)<br>Out[4]: "= {'one': 1, 'two': 2, 'three': 3}"<br><br>In [5= ]: d.values()<br>Out[5]: dict_values([1, 2, 3])<br><br>In [6]: d.keys()<br>= Out[6]: dict_keys(['one', 'two', 'three'])<br><br>I= n [7]: d.items()<br>Out[7]: dict_items([('one', 1), ('two',= 2), ('three', 3)])<br></span><br></div><div>Order IS preserved.<br= ><br></div><div>So presumably iPython is calling sorted() or some such when= displaying a dict. <br><br></div><div>Is that that case? Is that documente= d anywhere?? I can't find it.<br><br></div><div>And with Python >=3D= 3.6, dict order is preserved, so it would probably be better to NOT mess w= ith dict order when displaying them in iPython.<br><br></div><div>SIDE NOTE= :<br></div><div><br>I had a bit of trouble finding this mailing list -- goo= gle still points to the old ones on <a href=3D"http://scipy.org" target=3D"= _blank">scipy.org</a>. -- maybe we can put a note on the home page of those= lists that they are been moved??<br><br></div><div>(I only noticed, 'c= ause the archives of those stop last March)<span class=3D"m_-64216508565975= 78850m_3404512757170262343HOEnZb"><font color=3D"#888888"><br><br></font></= span></div><span class=3D"m_-6421650856597578850m_3404512757170262343HOEnZb= "><font color=3D"#888888"><div>-Chris<br></div><div><br></div><div><br></di= v><div><br><br></div><div><br>-- <br><div class=3D"m_-6421650856597578850m_= 3404512757170262343m_-4512783311611731130gmail_signature"><br>Christopher B= arker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NO= S/OR&R =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"tel:(206)%20= 526-6959" value=3D"+12065266959" target=3D"_blank">(206) 526-6959</a>=C2=A0= =C2=A0 voice<br>7600 Sand Point Way NE =C2=A0=C2=A0<a href=3D"tel:(206)%205= 26-6329" value=3D"+12065266329" target=3D"_blank">(206) 526-6329</a>=C2=A0= =C2=A0 fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0<a href=3D"= tel:(206)%20526-6317" value=3D"+12065266317" target=3D"_blank">(206) 526-63= 17</a>=C2=A0=C2=A0 main reception<br><br><a href=3D"mailto:Chris.Barker@noa= a.gov" target=3D"_blank">[email protected]</a></div> </div></font></span></div></div> <br></div></div>______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt= hon.org</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor= eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip= ython-dev</a><br> <br></blockquote></div><br></div> <br>______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt= hon.org</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor= eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip= ython-dev</a><br> <br></blockquote></div><br><br clear=3D"all"><br>-- <br><div class=3D"m_-64= 21650856597578850gmail_signature" data-smartmail=3D"gmail_signature"><br>Ch= ristopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division= <br>NOAA/NOS/OR&R =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"t= el:(206)%20526-6959" value=3D"+12065266959" target=3D"_blank">(206) 526-695= 9</a>=C2=A0=C2=A0 voice<br>7600 Sand Point Way NE =C2=A0=C2=A0<a href=3D"te= l:(206)%20526-6329" value=3D"+12065266329" target=3D"_blank">(206) 526-6329= </a>=C2=A0=C2=A0 fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0<= a href=3D"tel:(206)%20526-6317" value=3D"+12065266317" target=3D"_blank">(2= 06) 526-6317</a>=C2=A0=C2=A0 main reception<br><br><a href=3D"mailto:Chris.= [email protected]" target=3D"_blank">[email protected]</a></div> </div> </div></div><br>______________________________<wbr>_________________<br> IPython-dev mailing list<br> <a href=3D"mailto:[email protected]">[email protected]</a><br> <a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor= eferrer" target=3D"_blank">https://mail.python.org/<wbr>mailman/listinfo/ip= ython-dev</a><br> <br></blockquote></div><br></div> --f403043a0bb80e7a730560a8bb25-- --===============8514200170101176997== 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 --===============8514200170101176997==--