From wes.turner at gmail.com Fri Dec 15 01:23:26 2017 From: wes.turner at gmail.com (Wes Turner) Date: Fri, 15 Dec 2017 01:23:26 -0500 Subject: [IPython-dev] . to print all entries in sorted(dir(obj)) behavior? Message-ID: How do I / is there a way to restore the . prints all entries in sorted(dir(obj)) behavior? Is there a way to configure the new python-prompt-toolkit to not require multiple keystrokes to list the inspectable API of a class or instance? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wes.turner at gmail.com Fri Dec 15 01:34:10 2017 From: wes.turner at gmail.com (Wes Turner) Date: Fri, 15 Dec 2017 01:34:10 -0500 Subject: [IPython-dev] . to print all entries in sorted(dir(obj)) behavior? In-Reply-To: References: Message-ID: On Fri, Dec 15, 2017 at 1:23 AM, Wes Turner wrote: > How do I / is there a way to restore the . prints all entries in > sorted(dir(obj)) behavior? > > Is there a way to configure the new python-prompt-toolkit to not require > multiple keystrokes to list the inspectable API of a class or instance? > Is there a way to get my .inputrc readline bindings to work in IPython? (Is there a way to restore the classic pre-python-prompt-toolkit completer functionality with a configuration setting?) Call me old-fashioned, but I'd rather have my .inputrc readline bindings than these new features, TBH. Ctrl-[ == Ctrl-A Ctrl-] == Ctrl-E Ctrl-right Ctrl-left I added this first stab at a (pseudo-stateful) parser, but it's probably not complete and lacking test cases: "detect key-bindings from .inputrc" https://github.com/jonathanslenders/python-prompt-toolkit/issues/56 https://gist.github.com/westurner/0491f7e2c6d91842c3bcd3925d911ff7 In the meantime, how could one restore the classic IPCompleter or even just rlcompleter? -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Mon Dec 18 20:08:46 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Mon, 18 Dec 2017 17:08:46 -0800 Subject: [IPython-dev] display of dicts? Message-ID: 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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan12343 at gmail.com Mon Dec 18 20:40:02 2017 From: nathan12343 at gmail.com (Nathan Goldbaum) Date: Mon, 18 Dec 2017 19:40:02 -0600 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: 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/terminal.html#configtrait-PlainTextFormatter.pprint On Mon, Dec 18, 2017 at 7:08 PM, Chris Barker 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 > > Chris.Barker at noaa.gov > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > https://mail.python.org/mailman/listinfo/ipython-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Mon Dec 18 20:56:56 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Mon, 18 Dec 2017 17:56:56 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: 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 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/ > terminal.html#configtrait-PlainTextFormatter.pprint > > > > On Mon, Dec 18, 2017 at 7:08 PM, Chris Barker > 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 >> >> Chris.Barker at noaa.gov >> >> _______________________________________________ >> IPython-dev mailing list >> IPython-dev at python.org >> https://mail.python.org/mailman/listinfo/ipython-dev >> >> > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > 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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan12343 at gmail.com Mon Dec 18 22:04:31 2017 From: nathan12343 at gmail.com (Nathan Goldbaum) Date: Mon, 18 Dec 2017 21:04:31 -0600 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: 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 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 > 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 >> 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 >>> >>> Chris.Barker at noaa.gov >>> >>> _______________________________________________ >>> IPython-dev mailing list >>> IPython-dev at python.org >>> https://mail.python.org/mailman/listinfo/ipython-dev >>> >>> >> >> _______________________________________________ >> IPython-dev mailing list >> IPython-dev at python.org >> 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 > > Chris.Barker at noaa.gov > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > https://mail.python.org/mailman/listinfo/ipython-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Mon Dec 18 23:19:57 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Mon, 18 Dec 2017 20:19:57 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: On Mon, Dec 18, 2017 at 7:04 PM, Nathan Goldbaum wrote: > Nope, I believe it's this: https://github.com/ipython/ipython/blob/ > dc9d1c679424589480bb83af64aa5ee21031d311/IPython/lib/pretty.py > I see, thanks! Though it does have the same behavior of sorting dicts -- you can see that in: ``_dict_pprinter_factory`` However as of cPYthon 3.6, and officially as of 3.7, dicts will maintain their insertion order. So we should probably remove the sorting from the _dict_pprinter_factory. -CHB > > > On Mon, Dec 18, 2017 at 7:56 PM, Chris Barker > 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 >> 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 >>> 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 >>>> >>>> Chris.Barker at noaa.gov >>>> >>>> _______________________________________________ >>>> IPython-dev mailing list >>>> IPython-dev at python.org >>>> https://mail.python.org/mailman/listinfo/ipython-dev >>>> >>>> >>> >>> _______________________________________________ >>> IPython-dev mailing list >>> IPython-dev at python.org >>> 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 >> >> Chris.Barker at noaa.gov >> >> _______________________________________________ >> IPython-dev mailing list >> IPython-dev at python.org >> https://mail.python.org/mailman/listinfo/ipython-dev >> >> > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > 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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From takowl at gmail.com Tue Dec 19 06:21:53 2017 From: takowl at gmail.com (Thomas Kluyver) Date: Tue, 19 Dec 2017 11:21:53 +0000 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: I think this is a tricky one, as the discussion on Python-dev is finding. Removing the sorting makes it easier to explain how dictionaries now work. But for a lot of real-world use cases, insertion order is not meaningful, and displaying a sorted dictionary is still going to be more useful. We'll probably have to make it optional, but I don't think it's at all obvious which should be the default. I think the sorting is probably preferable more of the time, but when trying to teach people about insertion order, you really don't want to have to switch to non-default behaviour. On 19 December 2017 at 04:19, Chris Barker wrote: > > > On Mon, Dec 18, 2017 at 7:04 PM, Nathan Goldbaum > wrote: > >> Nope, I believe it's this: https://github.com/ipython/ipy >> thon/blob/dc9d1c679424589480bb83af64aa5ee21031d311/IPython/lib/pretty.py >> > > I see, thanks! Though it does have the same behavior of sorting dicts -- > you can see that in: > > ``_dict_pprinter_factory`` > > However as of cPYthon 3.6, and officially as of 3.7, dicts will maintain > their insertion order. > > So we should probably remove the sorting from the _dict_pprinter_factory. > > -CHB > > > > >> >> >> On Mon, Dec 18, 2017 at 7:56 PM, Chris Barker >> 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 >>> 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 >>>> 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 >>>>> >>>>> Chris.Barker at noaa.gov >>>>> >>>>> _______________________________________________ >>>>> IPython-dev mailing list >>>>> IPython-dev at python.org >>>>> https://mail.python.org/mailman/listinfo/ipython-dev >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> IPython-dev mailing list >>>> IPython-dev at python.org >>>> 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 >>> >>> Chris.Barker at noaa.gov >>> >>> _______________________________________________ >>> IPython-dev mailing list >>> IPython-dev at python.org >>> https://mail.python.org/mailman/listinfo/ipython-dev >>> >>> >> >> _______________________________________________ >> IPython-dev mailing list >> IPython-dev at python.org >> 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 > > Chris.Barker at noaa.gov > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > https://mail.python.org/mailman/listinfo/ipython-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Tue Dec 19 10:37:37 2017 From: chris.barker at noaa.gov (Chris Barker - NOAA Federal) Date: Tue, 19 Dec 2017 07:37:37 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: Message-ID: <4573660518963752835@unknownmsgid> > On Dec 19, 2017, at 3:23 AM, Thomas Kluyver wrote: > > I think this is a tricky one, as the discussion on Python-dev is finding. Indeed. But I think with iPython, at least it?s less likely that people are using the pretty printed results in a meaningful way. > But for a lot of real-world use cases, insertion order is not meaningful, and displaying a sorted dictionary is still going to be more useful. Maybe ? but for many dicts, the default sort order isn?t any better than arbitrary anyway. In my mind, the reason to have sorted dicts for pretty print in the first place was to get consistency? not sorting per se. And we now get that out of the box. > We'll probably have to make it optional, but I don't think it's at all obvious which should be the default. I think the sorting is probably preferable more of the time, but when trying to teach people about insertion order, you really don't want to have to switch to non-default behaviour. Exactly. +1 for making sorting non-default. But it is a change .. maybe not worth it. -CHB From takowl at gmail.com Tue Dec 19 10:45:59 2017 From: takowl at gmail.com (Thomas Kluyver) Date: Tue, 19 Dec 2017 15:45:59 +0000 Subject: [IPython-dev] display of dicts? In-Reply-To: <4573660518963752835@unknownmsgid> References: <4573660518963752835@unknownmsgid> Message-ID: On 19 December 2017 at 15:37, Chris Barker - NOAA Federal < chris.barker at noaa.gov> wrote: > > On Dec 19, 2017, at 3:23 AM, Thomas Kluyver wrote: > > > > I think this is a tricky one, as the discussion on Python-dev is finding. > > Indeed. But I think with iPython, at least it?s less likely that > people are using the pretty printed results in a meaningful way. > I think there's less danger of us breaking someone's *code* that relies on dictionary presentation. But it's more important for us to think about what's useful for human interpretation, since IPython is all about the interface. > > But for a lot of real-world use cases, insertion order is not > meaningful, and displaying a sorted dictionary is still going to be more > useful. > > Maybe ? but for many dicts, the default sort order isn?t any better > than arbitrary anyway. In my mind, the reason to have sorted dicts for > pretty print in the first place was to get consistency? not sorting > per se. And we now get that out of the box. > I disagree with that. Consistency is part of it, but I think the sorting is often helpful in itself. It's much easier to see if the dictionary has a key 'foo' if it's shown in alphabetical order than if it's not. The new dict also only gives you consistency if the data going into it is consistently ordered. If you are building a dictionary of filenames with os.listdir(), for example, order is not guaranteed. Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Tue Dec 19 12:24:24 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Tue, 19 Dec 2017 09:24:24 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: On Tue, Dec 19, 2017 at 7:45 AM, Thomas Kluyver wrote: > I think there's less danger of us breaking someone's *code* that relies on > dictionary presentation. But it's more important for us to think about > what's useful for human interpretation, since IPython is all about the > interface. > exactly. > I disagree with that. Consistency is part of it, but I think the sorting >> is often helpful in itself. It's much easier to see if the dictionary has a >> key 'foo' if it's shown in alphabetical order than if it's not. >> > > The new dict also only gives you consistency if the data going into it is > consistently ordered. If you are building a dictionary of filenames with > os.listdir(), for example, order is not guaranteed. > but whether default sort order of the keys is meaningful is a happy coincidence -- if the keys happen to be strings for which alphabetization makes sense, then great. If they are anything else, then not so great. Granted, string keys where alphabetization makes sense are pretty darn common, but still a "special case" In fact, I discovered this with this example, which I used in my intro to Python class to demonstrate dict's arbitrary order: In python 2.7: In [*1*]: d = {"one": 1, "two": 2, "three": 3} In [*2*]: d Out[*2*]: {'one': 1, 'three': 3, 'two': 2} In [*3*]: d.keys() Out[*3*]: ['three', 'two', 'one'] Interesting that the display version is different than the d.keys() version -- but I just thought that was a nice demo of "dicts are arbitrary order" Then, in Python3.6, which I am now using for teaching: In [*1*]: d = {"one": 1, "two": 2, "three": 3} In [*2*]: d Out[*2*]: {'one': 1, 'three': 3, 'two': 2} In [*3*]: d.keys() Out[*3*]: dict_keys(['one', 'two', 'three']) In [*4*]: print(d) {'one': 1, 'two': 2, 'three': 3} Huh? d.keys() is preserving order, print is preserving order, but plain display is not. it took me some time to realize that the display order was alphabetical, and then I figured that iPython must be sorting them, which then led me to the fact that the stdlib pprint sorts them too. I have been suing iPython for many years, and had never noticed that display used something other than "str" or "repr", nor that pprint sorted dicts. Still not sure if we should change it, but I don't think sorting dicts based on default sort of keys is an obviously "best" way to present a dict. -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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From takowl at gmail.com Tue Dec 19 12:37:55 2017 From: takowl at gmail.com (Thomas Kluyver) Date: Tue, 19 Dec 2017 17:37:55 +0000 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: On 19 December 2017 at 17:24, Chris Barker wrote: > Granted, string keys where alphabetization makes sense are pretty darn > common, but still a "special case" > I'd argue that they're common enough to be the typical case, though perhaps my definition of 'makes sense' is a bit broader than yours. And sorting can also make sense for numeric keys. > In fact, I discovered this with this example, which I used in my intro to > Python class to demonstrate dict's arbitrary order > I think this is exactly the tension we're facing. People teaching intro to Python courses want to show what a dictionary *is*, and you don't want IPython's features to obscure that. But other than learning about dictionaries, I suspect that sorted order is useful more often than insertion order. I'm leaning slightly towards making insertion order the default in Python 3.7 - it will be meaningful some of the time, and it is now part of what a dict is - but I think we should ensure the same release adds an easy way to switch back to displaying sorted dicts. Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Dec 19 12:50:28 2017 From: steve at holdenweb.com (Steve Holden) Date: Tue, 19 Dec 2017 17:50:28 +0000 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: On Tue, Dec 19, 2017 at 5:37 PM, Thomas Kluyver wrote: > On 19 December 2017 at 17:24, Chris Barker wrote: > >> Granted, string keys where alphabetization makes sense are pretty darn >> common, but still a "special case" >> > > I'd argue that they're common enough to be the typical case, though > perhaps my definition of 'makes sense' is a bit broader than yours. And > sorting can also make sense for numeric keys. > > >> In fact, I discovered this with this example, which I used in my intro to >> Python class to demonstrate dict's arbitrary order >> > > I think this is exactly the tension we're facing. People teaching intro to > Python courses want to show what a dictionary *is*, and you don't want > IPython's features to obscure that. But other than learning about > dictionaries, I suspect that sorted order is useful more often than > insertion order. > > I'm leaning slightly towards making insertion order the default in Python > 3.7 - it will be meaningful some of the time, and it is now part of what a > dict is - but I think we should ensure the same release adds an easy way to > switch back to displaying sorted dicts. > ?What about adding a "sorted" method to dicts that produces a dict with the same keys but the keys inserted ?in sorted order? regards Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Tue Dec 19 12:51:32 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Tue, 19 Dec 2017 09:51:32 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: On Tue, Dec 19, 2017 at 9:37 AM, Thomas Kluyver wrote: > I'm leaning slightly towards making insertion order the default in Python > 3.7 - it will be meaningful some of the time, and it is now part of what a > dict is - but I think we should ensure the same release adds an easy way to > switch back to displaying sorted dicts. > Sounds like a good plan. while we're at it -- could we add a way to specify a sort key function? -CHB -- 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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Tue Dec 19 12:55:34 2017 From: chris.barker at noaa.gov (Chris Barker) Date: Tue, 19 Dec 2017 09:55:34 -0800 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: On Tue, Dec 19, 2017 at 9:50 AM, Steve Holden wrote: > > ?What about adding a "sorted" method to dicts that produces a dict with > the same keys but the keys inserted ?in sorted order? > That would be a job for python-dev, yes? And maybe .sort() that sorts in place instead -- similar to lists. Too bad that the plain sorted() function only gives you the keys.. though there is dict(sorted(d.items())) to get a sorted dict. -CHB -- 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 Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Dec 19 12:58:15 2017 From: steve at holdenweb.com (Steve Holden) Date: Tue, 19 Dec 2017 17:58:15 +0000 Subject: [IPython-dev] display of dicts? In-Reply-To: References: <4573660518963752835@unknownmsgid> Message-ID: I've just "run it up the flagpole" on python-dev, so we'll see if anyone salutes. Steve Holden On Tue, Dec 19, 2017 at 5:55 PM, Chris Barker wrote: > On Tue, Dec 19, 2017 at 9:50 AM, Steve Holden wrote: > >> >> ?What about adding a "sorted" method to dicts that produces a dict with >> the same keys but the keys inserted ?in sorted order? >> > > That would be a job for python-dev, yes? > > And maybe .sort() that sorts in place instead -- similar to lists. > > Too bad that the plain sorted() function only gives you the keys.. though > there is > > dict(sorted(d.items())) > > > to get a sorted dict. > > > -CHB > > -- > > 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 > > Chris.Barker at noaa.gov > > _______________________________________________ > IPython-dev mailing list > IPython-dev at python.org > https://mail.python.org/mailman/listinfo/ipython-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: