[TIP] dicts in doctests

Fred Drake fdrake at gmail.com
Wed Sep 17 19:15:33 PDT 2008

On Wed, Sep 17, 2008 at 9:52 PM, Barry Warsaw <barry at python.org> wrote:
> Right, good point.  Be careful though because I think pprint's sorting is
> broken in Python 2.4.

With Python 2.4 and earlier, dicts for which the standard repr fit
within the available space without being stacked did not get their
keys sorted.  Stacked displays were sorted just fine.

One approach would be to always use the width control to force the
stacked display.  This works for all versions:

  >>> import pprint
  >>> def display(ob):
  ...     pprint.pprint(ob, width=1)


Fred L. Drake, Jr. <fdrake at gmail.com>
"Chaos is the score upon which reality is written." --Henry Miller

More information about the testing-in-python mailing list