[TIP] dicts in doctests

Barry Warsaw barry at python.org
Wed Sep 17 18:52:53 PDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sep 17, 2008, at 9:51 PM, Fred Drake wrote:

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

Right, good point.  Be careful though because I think pprint's sorting  
is broken in Python 2.4.

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSNG0dXEjvBPtnXfVAQLMRAP+LOMLdE8Bt+ER6Vs0SKe/ijWb+drQop0N
Noy/3x8Ty4DftG6lKl17YuM9oY8cvJ08ZBILS30DtSCvMyxisyJWj0lJH6lv595S
DIUUBBRmRpMlwCn4wtJpbBxUrfOg8Tqmdu7lK1T5f0kZvTtCYVqL1Fpyv29SjVKN
uA59WchMzSc=
=lPzP
-----END PGP SIGNATURE-----



More information about the testing-in-python mailing list