rafal chlopek
rafal chlopek

Reputation: 579

How to capture cell's output in Databricks notebook

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?

Upvotes: 4

Views: 5860

Answers (1)

rafal chlopek
rafal chlopek

Reputation: 579

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)

Upvotes: 4

Related Questions