Python 如何在 Jupyter 笔记本中包装代码/文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36419342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to wrap code/text in Jupyter notebooks
提问by Anuj Gupta
回答by Dan
Find your configuration directory via jupyter --config-dir
(mine is ~/.jupyter
). Then edit or create nbconfig/notebook.json
to add the following:
通过jupyter --config-dir
(我的是~/.jupyter
)找到您的配置目录。然后编辑或创建nbconfig/notebook.json
以添加以下内容:
{
"MarkdownCell": {
"cm_config": {
"lineWrapping": true
}
},
"CodeCell": {
"cm_config": {
"lineWrapping": true
}
}
}
(If you have something else in it, ensure you have valid JSON with no trailing commas after }
s.)
(如果您有其他内容,请确保您有有效的 JSON,}
s后没有尾随逗号。)
Restart Jupyter and reload your notebook.
重新启动 Jupyter 并重新加载您的笔记本。
回答by eden
In addition to Dan's answer, you can apply line wrapping for all cells(code or markdown) by specifying the top object as Cell. Adding the code below to your ~/.jupyter/nbconfig/notebook.json
除了 Dan 的回答之外,您还可以通过将顶部对象指定为 Cell 来为所有单元格(代码或降价)应用换行。将下面的代码添加到您的~/.jupyter/nbconfig/notebook.json
{
"Cell": {
"cm_config": {
"lineWrapping": true
}
}
}
Ex: This is my cell config
例如:这是我的单元格配置
{
"Cell": {
"cm_config": {
"lineNumbers": false,
"lineWrapping": true
}
}
}
回答by Robert Ben Parkinson
Shortest Answer Ever
有史以来最短的答案
Try adding a ' \ ' in between the lines of code you need to split.
尝试在需要拆分的代码行之间添加一个“\”。
This allows you to split your code over different lines and helps it look prettier.
这允许您将代码拆分为不同的行并使其看起来更漂亮。