[TIP] dicts in doctests

Fred Drake fdrake at gmail.com
Wed Sep 17 18:51:07 PDT 2008


On Wed, Sep 17, 2008 at 9:02 PM, Barry Warsaw <barry at python.org> wrote:
>>>> sorted(dict.items())

The pprint module is also very handy:

  >>> import pprint
  >>> pprint.pprint({'x': 1, 'y': 2})
  {'x': 1, 'y': 2}

(The ordering is controlled by the pprint module; it will be sorted by
the keys.)

The pprint.pprint function's width argument is also helpful at times:

  >>> pprint.pprint({'x': 1, 'y': 2}, width=1)
  {'x': 1,
   'y': 2}


 -Fred

-- 
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