Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying all output with linebreaks in Google Colab

I am trying to show all output of a cell in my Google Colab Notebook.

I found the setting for Jupyter Notebooks which displays all of the output and not only the last line:

from IPython.core.interactiveshell import InteractiveShell

InteractiveShell.ast_node_interactivity = "all"

However, the output is not separated by a line break which causes problem similar to the following

in: 
a = 3
a 
a+1 

out:
34

The desired output would be something more like:

out:
3
4

How can I make all distinct outputs separated by a line break? Is this possible in Jupyter Notebooks / Google Colab?

like image 383
Dominique Paul Avatar asked Oct 13 '18 16:10

Dominique Paul


People also ask

How do I display output in Google Colab?

Working with Google Sheets Colab also supports rich outputs such as charts. Type in the following code in the Code cell. Note that the graphical output is shown in the output section of the Code cell. Likewise, you will be able to create and display several types of charts throughout your program code.

What does %% capture do in Colab?

Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.

How do I see all rows in Google Colab?

use pd. set_option('max_colwidth', <width>) for column width & pd. set_option('max_rows', <rows>) for number of rows. Save this answer.

How do you run all cells at once in Google Colab?

You can also run only a part of the cell by selecting it and pressing the Runtime > Run Selection button or using the keyboard shortcut Ctrl + Shift + Enter .


1 Answers

You could try adding a print in between

a=3
a
print()
a+1

Or simply, print the two lines

a=3
print(a)
print(a+1)
like image 112
Anirban Mukherjee Avatar answered Nov 13 '22 23:11

Anirban Mukherjee