Show More
@@ -65,6 +65,21 b' There are also two more powerful display methods:' | |||
|
65 | 65 | Displays the object as a side effect; the return value is ignored. If this |
|
66 | 66 | is defined, all other display methods are ignored. |
|
67 | 67 | |
|
68 | To customize how the REPL pretty-prints your object, add a `_repr_pretty_` | |
|
69 | method to the class. The method should accept a pretty printer, and a boolean | |
|
70 | that indicates whether the printer detected a cycle. The method should act on | |
|
71 | the printer to produce your customized pretty output. Here is an example:: | |
|
72 | ||
|
73 | class MyObject(object): | |
|
74 | ||
|
75 | def _repr_pretty_(self, p, cycle): | |
|
76 | if cycle: | |
|
77 | p.text('MyObject(...)') | |
|
78 | else: | |
|
79 | p.text('MyObject[...]') | |
|
80 | ||
|
81 | For details, see :py:mod:`IPython.lib.pretty`. | |
|
82 | ||
|
68 | 83 | Formatters for third-party types |
|
69 | 84 | -------------------------------- |
|
70 | 85 |
General Comments 0
You need to be logged in to leave comments.
Login now