##// END OF EJS Templates
add --no-display flag to %%capture...
Paul Ivanov -
Show More
@@ -1166,13 +1166,17 b' python-profiler package from non-free.""")'
1166 1166 @magic_arguments.argument('--no-stdout', action="store_true",
1167 1167 help="""Don't capture stdout."""
1168 1168 )
1169 @magic_arguments.argument('--no-display', action="store_true",
1170 help="""Don't capture IPython's rich display."""
1171 )
1169 1172 @cell_magic
1170 1173 def capture(self, line, cell):
1171 """run the cell, capturing stdout/err"""
1174 """run the cell, capturing stdout, stderr, and IPython's rich display() calls."""
1172 1175 args = magic_arguments.parse_argstring(self.capture, line)
1173 1176 out = not args.no_stdout
1174 1177 err = not args.no_stderr
1175 with capture_output(out, err) as io:
1178 disp = not args.no_display
1179 with capture_output(out, err, disp) as io:
1176 1180 self.shell.run_cell(cell)
1177 1181 if args.output:
1178 1182 self.shell.user_ns[args.output] = io
@@ -65,7 +65,17 b' class RichOutput(object):'
65 65
66 66
67 67 class CapturedIO(object):
68 """Simple object for containing captured stdout/err StringIO objects"""
68 """Simple object for containing captured stdout/err and rich display StringIO objects
69
70 Each instance `c` has three attributes:
71
72 c.stdout : standard output as a string
73 c.stderr : standard error as a string
74 c.outputs: a list of rich display outputs
75
76 Additionally, there's a `c.show()` method which will print all of the
77 above in the same order, and can be invoked simply via `c()`.
78 """
69 79
70 80 def __init__(self, stdout, stderr, outputs=None):
71 81 self._stdout = stdout
@@ -130,7 +140,7 b' class capture_output(object):'
130 140 self.save_display_pub = None
131 141 self.display = False
132 142
133 stdout = stderr = outputs = False
143 stdout = stderr = outputs = None
134 144 if self.stdout:
135 145 stdout = sys.stdout = StringIO()
136 146 if self.stderr:
@@ -4,6 +4,9 b''
4 4
5 5 This document describes in-flight development work.
6 6
7 - `%%capture` cell magic now captures the rich display output, not just
8 stdout/stderr
9
7 10
8 11 Backwards incompatible changes
9 12 ------------------------------
General Comments 0
You need to be logged in to leave comments. Login now