How to capture cell's output in Databricks notebook

Viewed 1651

I tried using: %%capture my_cap but it gives an error:

TypeError: run_cell() missing 1 required positional argument: 'raw_cell'

So it's unusable :-( Any other options out there?

1 Answers

In the first cell include this:

from IPython.utils.capture import CapturedIO   
capture = CapturedIO(sys.stdout, sys.stderr)
...
...
# at the end of desired output:
cmem = capture.stdout

In the 2nd cell you can access variable cmem:

print(cmem)
Related