2024-05-17 03:21:41 发布
网友
我使用jupyter笔记本来编写python代码。有没有办法将文本/代码包装在jupyter笔记本的代码单元中?
图片如下。
“自动换行”是指“文本在MS word中的换行方式”
除了Dan的答案之外,还可以通过将顶部对象指定为Cell来对所有单元格应用换行(代码或标记)。将下面的代码添加到您的~/.jupyter/nbconfig/notebook.json
~/.jupyter/nbconfig/notebook.json
{ "Cell": { "cm_config": { "lineWrapping": true } } }
这是我的手机配置
{ "Cell": { "cm_config": { "lineNumbers": false, "lineWrapping": true } } }
尝试在需要拆分的代码行之间添加“\”。
这允许您将代码分成不同的行,并帮助它看起来更漂亮。
通过jupyter --config-dir找到配置目录(我的是~/.jupyter)。然后编辑或创建nbconfig/notebook.json以添加以下内容:
jupyter --config-dir
~/.jupyter
nbconfig/notebook.json
{ "MarkdownCell": { "cm_config": { "lineWrapping": true } }, "CodeCell": { "cm_config": { "lineWrapping": true } } }
(如果其中还有其他内容,请确保在}s之后没有尾随逗号的有效JSON。)
}
重新启动Jupyter并重新加载笔记本。
来源:https://github.com/jupyter/notebook/issues/106
除了Dan的答案之外,还可以通过将顶部对象指定为Cell来对所有单元格应用换行(代码或标记)。将下面的代码添加到您的
~/.jupyter/nbconfig/notebook.json
这是我的手机配置
最短的答案
尝试在需要拆分的代码行之间添加“\”。
这允许您将代码分成不同的行,并帮助它看起来更漂亮。
通过
jupyter --config-dir
找到配置目录(我的是~/.jupyter
)。然后编辑或创建nbconfig/notebook.json
以添加以下内容:(如果其中还有其他内容,请确保在
}
s之后没有尾随逗号的有效JSON。)重新启动Jupyter并重新加载笔记本。
来源:https://github.com/jupyter/notebook/issues/106
相关问题 更多 >
编程相关推荐