'Google Colab code change always produces "TabError: Inconsistent use of tab and spaces in indentation"

When I make even a simple change in a file checked out in /root/model/ in Google Colab environment Intro, I get

"TabError: Inconsistent use of tab and spaces in indentation"

I've set the editor in Colab settings to show 4 spaces for a Tab, and to show line-numbers (the Colab editor doesn't have many settings to change), and the line that I added looks perfectly indented. I can't tell why/how it's not indented.

Does anyone come across this issue?

How do you change files (in code that's checkout out in /content/ or /root/ from a model-repo) as the Colab-editor gives error on very basic of changes?



Solution 1:[1]

I came across this issue. I have the feeling that something goes wrong from time to time when copying and pasting code lines, but I do not have a precise diagnosis.

Changing the tabs into spaces solved the issue for me.

Solution 2:[2]

SOLVE: I removed the space before and after the line with the problem and solved

Solution 3:[3]

This is a bug in colab where it will repopulate an indentation done from the keyboard shortcuts with the wrong character. It starts if you paste tab-delimited code into a Jupyter Notebook and then insert a space-delimited line from the editor. The code has to be all tabs or all spaces in a cell, but the editor inserts spaces in exist lines with leading tabs. Solution is to reformat any inserted code. If you use darkmode in colab, the leading characters can be hard to see.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vitality
Solution 2 Charly Braga Ventura
Solution 3 vwvan