As discussed in the chat, there is no easy way to do this. Since the function prints the values, the only thing you can do is output Capture + Then output. There are several issues in jupyter that may interest you.
https://github.com/jupyter/notebook/issues/2049
https://github.com/ipython/ipython/issues/6516
Output capture
Data output can be performed in several ways.
1. Print overload method
import sys data = "" def myprint(value, *args, sep=' ', end='\n', file=sys.stdout, flush=False): global data current_text = value + " ".join(map(str, args)) + "\n" data += current_text original_print = print print = myprint def testing(): for i in range(1,1000): print ("i =", i) testing() original_print("The output from testing function is", data)
2. Capturing output using StringIO
from cStringIO import StringIO import sys class Capturing(list): def __enter__(self): self._stdout = sys.stdout sys.stdout = self._stringio = StringIO() return self def __exit__(self, *args): self.extend(self._stringio.getvalue().splitlines()) del self._stringio
Using:
with Capturing() as output: do_something(my_object)
3. Capturing output using redirect_stdout
import io from contextlib import redirect_stdout f = io.StringIO() with redirect_stdout(f): do_something(my_object) out = f.getvalue()
4. Capture with the capture command %%

Paging output
You can use magin %page
%page -r <variablename>
https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-page
Or you can use ipython code
from IPython.core import page page.page(variable)
See below for more details.
PS: Some useful topics
How to write stdout output from Python function call?
How to redirect function output in python
https://github.com/ipython/ipython/wiki/Cookbook:-Sending-built-in-help-to-the-pager
python overload