Re: Incompatible change discussion: Pretty printing of ordered dict.
Pietro Terna <[email protected]> Fri, 4 Aug 2017 22:48:31 +0200
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============6451748814252545913==
Content-Type: multipart/alternative;
boundary="------------F323BA43E0EB1990C4E96243"
Content-Language: en-US
This is a multi-part message in MIME format.
--------------F323BA43E0EB1990C4E96243
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Dear all,
just to understand ...
Why in Idle the result is different?
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> d = {'c':3,'b':2,'a':1}
>>> d
{'c': 3, 'b': 2, 'a': 1}
>>>
Best, Pietro
Il 04/08/17 20:23, Yarko Tymciurak ha scritto:
> In [16]: d = {'c':3,'b':2,'a':1}
>
> In [17]: d
> Out[17]: {'a': 1, 'b': 2, 'c': 3}
>
> In [18]: repr(d)
> Out[18]: "{'c': 3, 'b': 2, 'a': 1}"
>
> In [19]: import pprint
>
> In [20]: pprint.pprint(d)
> {'a': 1, 'b': 2, 'c': 3}
>
> In [21]: print(d)
> {'c': 3, 'b': 2, 'a': 1}
>
> In [22]: print(pprint.pformat(d))
> {'a': 1, 'b': 2, 'c': 3}
>
>
> On Fri, Aug 4, 2017 at 10:21 AM, Steve Holden <[email protected]
> <mailto:[email protected]>> wrote:
>
> 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 ordering is
> available if required. S
>
> Sent from my iPhone
>
> On 4 Aug 2017, at 15:36, Wes Turner <[email protected]
> <mailto:[email protected]>> wrote:
>
>> ```python
>> repr(dict)
>>
>> import pprint
>> pprint.pprint(dict)
>> print(pprint.pformat(dict)
>> ```
>>
>> On Friday, August 4, 2017, MinRK <[email protected]
>> <mailto:[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 dict
>> ordering, such as by iterating through the dict , e.g.
>> `list(dict)`.
>>
>> -Min
>>
>> On Thu, Aug 3, 2017 at 6:38 PM, Carl Smith
>> <[email protected]> wrote:
>>
>> I'm with Thomas.
>>
>>
>> On Wed, 2 Aug 2017 22:30 Wes Turner,
>> <[email protected]> wrote:
>>
>> Maybe a SORT_DICT_KEYS bool configuration setting?
>> Really practically only in order to teach:
>>
>> - dict
>> -
>> https://docs.python.org/3/tutorial/datastructures.html#dictionaries
>> <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#envvar-PYTHONHASHSEED>
>> -
>> https://docs.python.org/3/using/cmdline.html#cmdoption-R
>> <https://docs.python.org/3/using/cmdline.html#cmdoption-R>
>> - collections.OrderedDict (is backwards compatible)
>> -
>> https://docs.python.org/3/library/collections.html#ordereddict-objects
>> <https://docs.python.org/3/library/collections.html#ordereddict-objects>
>>
>>
>>
>> On Wednesday, August 2, 2017, Matthias Bussonnier
>> <[email protected]> wrote:
>>
>> Hi all,
>>
>> 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.
>>
>> 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.
>>
>> https://github.com/ipython/ipython/issues/10110
>> <https://github.com/ipython/ipython/issues/10110>
>>
>> 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.
>>
>> If you care about the above subject, please have
>> your voice heard in
>> above issue.
>>
>> Thanks,
>> --
>> Matthias
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/ipython-dev
>> <https://mail.python.org/mailman/listinfo/ipython-dev>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/ipython-dev
>> <https://mail.python.org/mailman/listinfo/ipython-dev>
>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/ipython-dev
>> <https://mail.python.org/mailman/listinfo/ipython-dev>
>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected] <mailto:[email protected]>
>> https://mail.python.org/mailman/listinfo/ipython-dev
>> <https://mail.python.org/mailman/listinfo/ipython-dev>
>
> _______________________________________________
> IPython-dev mailing list
> [email protected] <mailto:[email protected]>
> https://mail.python.org/mailman/listinfo/ipython-dev
> <https://mail.python.org/mailman/listinfo/ipython-dev>
>
>
>
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/ipython-dev
--
The world is full of interesting problems to be solved!
Home page: http://terna.to.it
Have a look to:
http://web-prod.santafe.edu/news-center/news/dangers-simplicity-complex-world
--------------F323BA43E0EB1990C4E96243
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<tt> Dear all,<br>
<br>
just to understand ...<br>
<br>
Why in Idle the result is different?<br>
<br>
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) <br>
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br>
Type "copyright", "credits" or "license()" for more information.<br>
>>> d = {'c':3,'b':2,'a':1}<br>
>>> d<br>
{'c': 3, 'b': 2, 'a': 1}<br>
>>> <br>
<br>
Best, Pietro<br>
</tt><br>
<div class="moz-cite-prefix">Il 04/08/17 20:23, Yarko Tymciurak ha
scritto:<br>
</div>
<blockquote type="cite"
cite="mid:CAJ+Z=PLv8---9i7YE6ejaGoL2so3Y5vaWxcivyQj-eXM5yAidw@mail.gmail.com">
<div dir="ltr">
<div>In [16]: d = {'c':3,'b':2,'a':1}</div>
<div><br>
</div>
<div>In [17]: d</div>
<div>Out[17]: {'a': 1, 'b': 2, 'c': 3}</div>
<div><br>
</div>
<div>In [18]: repr(d)</div>
<div>Out[18]: "{'c': 3, 'b': 2, 'a': 1}"</div>
<div><br>
</div>
<div>In [19]: import pprint</div>
<div><br>
</div>
<div>In [20]: pprint.pprint(d)</div>
<div>{'a': 1, 'b': 2, 'c': 3}</div>
<div><br>
</div>
<div>In [21]: print(d)</div>
<div>{'c': 3, 'b': 2, 'a': 1}</div>
<div><br>
</div>
<div>In [22]: print(pprint.pformat(d))</div>
<div>{'a': 1, 'b': 2, 'c': 3}</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Aug 4, 2017 at 10:21 AM, Steve
Holden <span dir="ltr"><<a
href="mailto:[email protected]" target="_blank"
moz-do-not-send="true">[email protected]</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="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 ordering is available if
required. S<br>
<br>
Sent from my iPhone</div>
<div>
<div class="h5">
<div><br>
On 4 Aug 2017, at 15:36, Wes Turner <<a
href="mailto:[email protected]" target="_blank"
moz-do-not-send="true">[email protected]</a>>
wrote:<br>
<br>
</div>
<blockquote type="cite">
<div>
<div>```python</div>
repr(dict)
<div><br>
</div>
<div>import pprint</div>
<div>pprint.pprint(dict)</div>
<div>print(pprint.pformat(dict)</div>
<div>```<br>
<br>
On Friday, August 4, 2017, MinRK <<a
href="mailto:[email protected]"
target="_blank" moz-do-not-send="true">[email protected]</a>>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0
0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">
<div dir="ltr">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 dict ordering,
such as by iterating through the dict , e.g.
`list(dict)`.
<div><br>
</div>
<div>-Min</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Aug 3, 2017
at 6:38 PM, Carl Smith <span dir="ltr"><<a
moz-do-not-send="true">[email protected]</a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex">
<p dir="ltr">I'm with Thomas. </p>
<div>
<div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Wed, 2 Aug 2017
22:30 Wes Turner, <<a
moz-do-not-send="true">[email protected]</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote"
style="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> - <a
href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries"
target="_blank"
moz-do-not-send="true">https://docs.python.org/3/tu<wbr>torial/datastructures.html#dic<wbr>tionaries</a></div>
<div>- <span
style="color:rgb(34,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,sans-serif;font-size:14px">PYTHONHASHSEED
/ -R</span></div>
<div><span
style="color:rgb(34,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,sans-serif;font-size:14px">
- </span><font
face="Roboto-Regular,
HelveticaNeue, Arial,
sans-serif" color="#222222"><span
style="font-size:14px"><a
href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED"
target="_blank"
moz-do-not-send="true">https://docs.python.org/3/us<wbr>ing/cmdline.html#envvar-PYTHON<wbr>HASHSEED</a></span></font></div>
<div><font face="Roboto-Regular,
HelveticaNeue, Arial,
sans-serif" color="#222222"><span
style="font-size:14px"> -
<a
href="https://docs.python.org/3/using/cmdline.html#cmdoption-R"
target="_blank"
moz-do-not-send="true">https://docs.python.org/3/usin<wbr>g/cmdline.html#cmdoption-R</a></span></font></div>
<div><font face="Roboto-Regular,
HelveticaNeue, Arial,
sans-serif" color="#222222"><span
style="font-size:14px">-
collections.OrderedDict
(is backwards compatible)</span></font></div>
<div><span
style="color:rgb(34,34,34);font-family:Roboto-Regular,HelveticaNeue,Arial,sans-serif;font-size:14px">
- <a
href="https://docs.python.org/3/library/collections.html#ordereddict-objects"
target="_blank"
moz-do-not-send="true">https://docs.python.org/3/li<wbr>brary/collections.html#ordered<wbr>dict-objects</a></span></div>
<div><font face="Roboto-Regular,
HelveticaNeue, Arial,
sans-serif" color="#222222"><span
style="font-size:14px"><br>
</span></font></div>
<div><font face="Roboto-Regular,
HelveticaNeue, Arial,
sans-serif" color="#222222"><span
style="font-size:14px"><br>
</span></font><br>
On Wednesday, August 2, 2017,
Matthias Bussonnier <<a
moz-do-not-send="true">[email protected]</a>>
wrote:<br>
<blockquote
class="gmail_quote"
style="margin: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="https://github.com/ipython/ipython/issues/10110"
target="_blank"
moz-do-not-send="true">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 moz-do-not-send="true">[email protected]</a><br>
<a
href="https://mail.python.org/mailman/listinfo/ipython-dev"
target="_blank"
moz-do-not-send="true">https://mail.python.org/mailma<wbr>n/listinfo/ipython-dev</a><br>
</blockquote>
</div>
______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a moz-do-not-send="true">[email protected]</a><br>
<a
href="https://mail.python.org/mailman/listinfo/ipython-dev"
rel="noreferrer"
target="_blank"
moz-do-not-send="true">https://mail.python.org/mailma<wbr>n/listinfo/ipython-dev</a><br>
</blockquote>
</div>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a moz-do-not-send="true">[email protected]</a><br>
<a
href="https://mail.python.org/mailman/listinfo/ipython-dev"
rel="noreferrer" target="_blank"
moz-do-not-send="true">https://mail.python.org/mailma<wbr>n/listinfo/ipython-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div><span>______________________________<wbr>_________________</span><br>
<span>IPython-dev mailing list</span><br>
<span><a href="mailto:[email protected]"
target="_blank" moz-do-not-send="true">[email protected]</a></span><br>
<span><a
href="https://mail.python.org/mailman/listinfo/ipython-dev"
target="_blank" moz-do-not-send="true">https://mail.python.org/<wbr>mailman/listinfo/ipython-dev</a></span><br>
</div>
</blockquote>
</div>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href="mailto:[email protected]"
moz-do-not-send="true">[email protected]</a><br>
<a
href="https://mail.python.org/mailman/listinfo/ipython-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://mail.python.org/<wbr>mailman/listinfo/ipython-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
IPython-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/ipython-dev">https://mail.python.org/mailman/listinfo/ipython-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
The world is full of interesting problems to be solved!
Home page: <a class="moz-txt-link-freetext" href="http://terna.to.it">http://terna.to.it</a>
Have a look to:
<a class="moz-txt-link-freetext" href="http://web-prod.santafe.edu/news-center/news/dangers-simplicity-complex-world">http://web-prod.santafe.edu/news-center/news/dangers-simplicity-complex-world</a></pre>
</body>
</html>
--------------F323BA43E0EB1990C4E96243--
--===============6451748814252545913==
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
--===============6451748814252545913==--