Working on Google Collaboratoy (colab) as Notebook, some cell results a long line text which is bigger than the screen resolution, so it is shown a scrollbar with no wrapping.
Does anyone know how to activate text wrapping to see all text without using scrollbar?
Thanks in advance.
Regards,
In text display, line wrap is continuing on a new line when a line is full, so that each line fits into the viewable window, allowing text to be read from top to bottom without any horizontal scrolling.
You can select the lines of code and press ( Ctrl + / ) to comment or uncomment your selected lines of code. You can also use triple single quotes ( ''' ) at the start and end of the code block you are interested to comment out. Save this answer.
There are two options here either you can just press the “Enter” key and leave a line of space in the between or you can use the br tag also called a line break.
Normally on my own machine, I put this the following css snippit in the ~/.jupyter/custom/custom.css
file.
pre {
white-space: pre-wrap;
}
But, the above does not work for google colab: I tried creating a file /usr/local/share/jupyter/custom/custom.css
, but this didn't work.
from IPython.display import HTML, display
def set_css():
display(HTML('''
<style>
pre {
white-space: pre-wrap;
}
</style>
'''))
get_ipython().events.register('pre_run_cell', set_css)
Explanation: As described in Google Colab advanced output , get_ipython().events.register('pre_run_cell', <function name>)
...
defines an execution hook that loads it [our custom
set_css()
function in our case] automatically each time you execute a cell
My interpretation is that you need to specify 'pre_run_cell'
as the first argument in the events.register
, which tells the events.register
function that you wish to run your custom set_css()
function before the contents of the cell is executed.
This answer was inspired by How to import CSS file into Google Colab notebook (Python3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With