Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 791
rafal chlopek Avatar asked Sep 07 '25 00:09

rafal chlopek


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)
like image 106
rafal chlopek Avatar answered Sep 10 '25 15:09

rafal chlopek