Reputation: 579
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
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