Python indent 2 - jupyterlab Version 3.2.1

Moving code to Jupyter … really cool setup. Reminds me of Mathematica notebooks.

There is a lot of information on the net on how to set the indent to 2 for the netbooks when working with Python. … but all of that information appears to be out of date. Setting settings seems to be an evolving feature. Here is a list so that others can avoid time trying it:

Things found in various docks, but did not work:

  1. in the settings menu set the text editor indent to 2 spaces. It was 4. The Python code editor ignores it.
  2. JavaScript code put in console window. Returns errors.
  3. variable to be put in startup file, ignored, perhaps I have the wrong file name
  4. function to be be put into said startup file, ditto
  5. code to put in the ‘code mirror’ section of the advanced settings, (article was for something else. I tried the variable name ‘indent’ but that did not work)

I have searched the forums here and have not found this topic. I apologize if I have missed it.

So gurus, how does a person go about setting the Python editor to indent 2 spaces? Thanks!

If you are trying to do settings in the Notebook, you need to edit the settings in ‘Notebook’. The ‘Text editor’ settings are for the editor that edits standalone code files.

I’m working in 3.2.0 and this works to have indent be two when writing a for loop in a notebook code cell:

    // Notebook
    // @jupyterlab/notebook-extension:tracker
    // Notebook settings.
    // **************************************

    // Code Cell Configuration
    // The configuration for all code cells.
    "codeCellConfig": {
        "autoClosingBrackets": false,
        "cursorBlinkRate": 530,
        "fontFamily": null,
        "fontSize": null,
        "lineHeight": null,
        "lineNumbers": false,
        "lineWrap": "off",
        "matchBrackets": true,
        "readOnly": false,
        "insertSpaces": true,
        "tabSize": 2,
    },

You can try it in your browser via the following steps by first launching from here.

To change to that go to ‘Settings’ > ‘Advanced Settings Editor’ > ‘Notebook’.
Then copy and paste all that is in the left panel into the right panel under ‘User Preferences’ on the right. Edit the "tabSize" setting to 2 and hit the save icon above in the upper right.
Now go edit a code cell in a notebook.

There’s related discussion about switching from tabs to spaces here that may help.

If the same thing fails in 3.2.1, then maybe it is broken?

2 Likes

Bless you Wayne. <Post must be at least 20 characters>