Message49169
The current format() method doesn't recursively apply
an overridden format() method when the width of the
object is too short.
This patch is designed to remove that limitation and
allow a pprint.PrettyPrinter sublcass that could, for
example, print all ints and longs in hex:
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels,
level):
if isinstance(object, int):
return hex(object), True, False
else:
return pprintmod.PrettyPrinter.format(
self, object, context, maxlevels,
level)
>>> mpp = MyPrettyPrinter()
>>> mpp.pprint(range(10))
[0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9]
>>> mpp.pprint(range(0x10000000,0x10000010))
[0x10000000,
0x10000001,
0x10000002,
0x10000003,
0x10000004,
0x10000005,
0x10000006,
0x10000007,
0x10000008,
0x10000009,
0x1000000a,
0x1000000b,
0x1000000c,
0x1000000d,
0x1000000e,
0x1000000f]
The attached file contains "svn diff --diff-cmd diff -
x -b Lib/pprint.py". |
|
Date |
User |
Action |
Args |
2007-08-23 15:44:53 | admin | link | issue1373762 messages |
2007-08-23 15:44:53 | admin | create | |
|