How to wrap code/text in Jupyter notebooks

后端 未结 3 1230
傲寒
傲寒 2020-12-04 07:10

I am using jupyter-notebooks for python coding. Is there a way to wrap text/code in a jupyter notebook code cell?

Picture provided below.

By wrap

相关标签:
3条回答
  • 2020-12-04 07:33

    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.

    0 讨论(0)
  • 2020-12-04 07:46

    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

    {
      "Cell": {
        "cm_config": {
          "lineWrapping": true
        }
      }
    }
    

    Ex: This is my cell config

    {
      "Cell": {
        "cm_config": {
          "lineNumbers": false,
          "lineWrapping": true
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-04 07:56

    Find your configuration directory via jupyter --config-dir (mine is ~/.jupyter). Then edit or create nbconfig/notebook.json to add the following:

    {
      "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.)

    Restart Jupyter and reload your notebook.

    Source: https://github.com/jupyter/notebook/issues/106

    0 讨论(0)
提交回复
热议问题