协作Google结果中的换行 [英] Line Wrapping in Collaboratory Google results
问题描述
使用Google Collaboratoy(可乐)作为Notebook,某些单元格产生的长行文本大于屏幕分辨率,因此显示的滚动条没有换行.
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?
先谢谢了.
关于
推荐答案
通常在我自己的计算机上,我将以下CSS片段放在~/.jupyter/custom/custom.css
文件中.
Normally on my own machine, I put this the following css snippit in the ~/.jupyter/custom/custom.css
file.
pre {
white-space: pre-wrap;
}
但是,以上方法不适用于google colab:我尝试创建文件/usr/local/share/jupyter/custom/custom.css
,但这不起作用.
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)
说明:如 Google Colab高级输出,get_ipython().events.register('pre_run_cell', <function name>)
...
定义了一个加载它的执行钩子[我们在我们的自定义
set_css()
函数中 情况]每次执行单元格时都会自动
defines an execution hook that loads it [our custom
set_css()
function in our case] automatically each time you execute a cell
我的解释是,您需要指定'pre_run_cell'
作为events.register
中的第一个参数,这告诉events.register
函数您希望在执行单元格内容之前运行自定义set_css()
函数
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.
此答案的灵感来自如何将CSS文件导入Google Colab笔记本(Python3)
这篇关于协作Google结果中的换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!