Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb21d60

Browse files
authored
Merge pull request #12823 from dsblank/master
Added clear kwarg to display()
2 parents e08519b + 154c40b commit bb21d60

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

IPython/core/display_functions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
120120
Set an id for the display.
121121
This id can be used for updating this display area later via update_display.
122122
If given as `True`, generate a new `display_id`
123+
clear : bool, optional
124+
Should the output area be cleared before displaying anything? If True,
125+
this will wait for additional output before clearing. [default: False]
123126
kwargs: additional keyword-args, optional
124127
Additional keyword-arguments are passed through to the display publisher.
125128
@@ -239,7 +242,8 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
239242
print(*objs)
240243
return
241244

242-
raw = kwargs.pop('raw', False)
245+
raw = kwargs.pop("raw", False)
246+
clear = kwargs.pop("clear", False)
243247
if transient is None:
244248
transient = {}
245249
if metadata is None:
@@ -263,6 +267,9 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
263267
if not raw:
264268
format = InteractiveShell.instance().display_formatter.format
265269

270+
if clear:
271+
clear_output(wait=True)
272+
266273
for obj in objs:
267274
if raw:
268275
publish_display_data(data=obj, metadata=metadata, **kwargs)

0 commit comments

Comments
 (0)