[TIP] dicts in doctests

Barry Warsaw barry at python.org
Wed Sep 17 19:19:45 PDT 2008


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

On Sep 17, 2008, at 10:15 PM, Fred Drake wrote:

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

Ah, I didn't know that.  Thanks for the tip!
- -Barry

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

iQCVAwUBSNG6wXEjvBPtnXfVAQLNKAP/cEMA1AgFSfA/CkFAEJQY8MXTztzeXaw4
48myito9XwmBpERAnczG3y9h6++Q4BaHKvOARApZ6mjNqaBweIVOZnXRRGF/7UGB
QYA4DCafH79cyZeT15pEuFdzpebVVSKP17FcHXi19thuzUh3DzOunzWB1XRhoqab
sXwUMZWB3gM=
=zwPX
-----END PGP SIGNATURE-----



More information about the testing-in-python mailing list