Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print into console terminal not into cell output of IPython Notebook

I would like to print into the terminal window that runs IPython Notebook and not into the cell output. Printing into cell output consumes more memory and slows down my system when I issue a substantial number of print calls. In essence, I would like this behaviour by design.

I have tried the following:

  1. I tried a different permutations of print and sys.stdout.write calls
  2. I looked at the IPython Notebook documentation here, here and here without help
  3. I have tried using this as a workaround but it seems to be only working on Python 2.7
like image 800
Matt Avatar asked Jun 09 '15 10:06

Matt


People also ask

How do you not show the output of a cell in Jupyter Notebook?

Hide cell inputs If you add the tag hide-input to a cell, then Jupyter Book will hide the cell but display the outputs.

How do I print from IPython notebook?

In JupyterLab select Help -> Launch classic notebook, then from your browser menu (e.g. 3 dot menu) choose print and print to pdf.

How do I suppress output in a Python notebook?

Put a ';' at the end of a line to suppress the printing of output.

How do I run IPython notebook in terminal?

To launch Jupyter Notebook App: Click on spotlight, type terminal to open a terminal window. Enter the startup folder by typing cd /some_folder_name . Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.


1 Answers

You have to redirect your output to the systems standard output device. This depends on your OS. On Mac that would be:

import sys
sys.stdout = open('/dev/stdout', 'w')

Type the above code in an IPython cell and evaluate it. Afterwards all output will show up in terminal.

like image 81
MaxPowers Avatar answered Oct 06 '22 08:10

MaxPowers