This is because the indentation is screwed up. For consistency the codemirror parser will make a red line if it's not indented 4 spaces (or if it's indented with tabs, depending on codemirror version). The parser has some edge case that indeed highlight only a few of theses lines in red, I won't go into details, but if you indent 4 spaces it will work.
You can either:
tab
alt
-click'n'drag
vertically to place multiple cursors in front of your code, and press space enough time to make the correct indent 4 space.Setting the indent to 2 is possible, but complex and not recommended. 4 space is the python norm.
This is the official solution from the Jupyter Notebook documentation:
Open your browser's JavaScript console and run the following snippet:
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
Reload the Notebook page
This fix is permanent.
To reverse the change repeat the process running this snippet:
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit: null} # only change here.
}
}
config.update(patch)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With