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

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?

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.

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

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.

SOLVED : I faced this issue when using google colaboratory the solution for me was to copy my code from google colab and paste it in sublime text 3 in .py file and in sublime go to View -> Indentation and click Convert Indentation to Tabs and recopy paste your code to google colab is should work

It just boils down to the use of tabs or spaces if you are copying and pasting e.g. from editors, IDEs, notepads, githubs, or anywhere. Just make sure you have either tabs or spaces in your script on colab just by selecting the script. You will see arrows or dots. After spending a lot of time I got to know 1 arrow == 8 spaces, I don't know about others. JUST MAKE SURE ONLY TABS OR SPACES in your scripts for consistency. Colab seems to fail to connect outside code while copying, may be.

Related

Is there a way to turn off suggestion popup when opening string in VS Code Jupyter Notebook

I am trying to disable a VS Code pop-up whenever I hit a quotes key (either ' or ", either open or closing). A screenshot is attached of the pop-up. I've been googling my heart out for this but can't seem to find what is driving this behaviour.
Things I've tried:
Set "editor.parameterHints.enabled":false to prevent annoying popups when I enter a function.
Set "editor.quickSuggestions": {"other": false, "comments": false, "strings": false}
Set "editor.snippetSuggestions": "none" just in case that was doing anything
The same behaviour is not replicated in a new workbook before running any cells, nor in a blank .py file. Files in the same directory are listed, which makes me think that at least part of the popup is coming from the file list. But the others really don't seem meaningful to me.
It ends up costing me a fairly large amount of keystrokes hitting esc every time, or going back to correct errors when I hit tab or enter before escaping. And is also just generally annoying. Any help would be appreciated.
Example image of pop-up:
EDIT:
The list of extensions I am currently working with excluding themes.
I have turned of all except those necessary for Jupyter Notebooks and still get the same behaviour:
adam-watters.vscode-color-pick
AndersEAndersen.html-class-suggestions
christian-kohler.path-intellisense
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
hediet.vscode-drawio kiteco.kite
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-vscode-remote.remote-wsl
njpwerner.autodocstring
ritwickdey.LiveServer
Shan.code-settings-sync
streetsidesoftware.code-spell-checker
WakaTime.vscode-wakatime
wmaurer.change-case
I had the same issue. This solved it for me: In VSCode settings, go to 'Extensions > Jupyter > Python Completion Trigger Characters'
Defaults were: .%'"
So I deleted the single and double quotes, restarted, and voila, no more annoying popups.

indentation issue python in sign detection script

I have a script with I try to detect STOP sign in the traffic, but I have a problem with indentation, and I don't know how to solve it...
Image with the code:
And error message:
You can clearly see (even if code-in-image is a no-no) line 24 has spaces, line 25 has tabs.
Make them all spaces.
You can't mix tab and space for indentation. Make all of them either space or tab.

How to 'see' / highlight tabs and spaces in PyCharm for checking indentation?

this may sound dumb, but I am still fairly new, is there clear way to spot if I have tabs or spaces in the wrong place with PyCharm?
Or even to display all tabs and spaces visually?
I just spent ages looking for problem with 'invalid syntax' error at Def line of function, I had thought it might still be some wrong indent, which I did have before, so checked this painstakingly and found nothing. In the end, was missing ) from end of function before this. I realised the coloured lines on right hand side show errors and got this one from there.
Also I understand you can mix tabs and 4 space character indents in PyCharm with no problem?
But if you use tab one line and 4 spaces the next with, for example, simple text editor, Python will say 'no I'm not going to run this because I'm a strict pedant and this is just too naughty'? Any other common sense best practice habits in this area?
How to 'see' / highlight tabs and spaces in PyCharm for checking indentation?
You can tell Pycharm to visually show tabs and spaces by going to View -> Active Editor -> Show Whitespaces:
Also I understand you can mix tabs and 4 space character indents in PyCharm with no problem?
Yes you can. But you shouldn't. Even if you choose to however, PyCharm will convert them all to spaces by default. You can change this behavior by going to Settings -> Editor -> Code Style -> Python and then selecting the Use tab character check box:
There's a setting to make white space visible in:
Settings -> Editor -> General -> Appearance -> Show whitespaces

indent with 'tab' button in python commandline

hi everyone :)
my problem is, up until now, i have exclusively used tabs to indent python, as i find it easier than spaces, but for no reason i know, python interactive prompt, the basic python.exe one, suddenly refuses to accept the tab button, all it does is flash the cursor. all i can think of is that my computer in suddenly treading the window like any other, using tab to cycle input things, in this case the single one. also, before now, i could use the up button to reach previously typed code, the if i submit that line with no changes, use the down button to access the line that came after it, but now up works, but as if i had changed the line, eg moves me back to the "bottom" of the list of inputs, so down doesn't work.... my question simply is: how do i get my good old tab and down button to work like i want them to again? :(
thanks xxx
If you are using Windows with the standard cmd.exe console (and it would have been helpful for you to have stated this up front) then you can use the TAB and arrow keys exactly as you desire.
I recently observed this behavior too, on Windows, using cmd.exe. It also happens with Console2 - an alternate shell I sometimes use.
Though I do always use spaces in normal code in an editor, I had been accustomed to using the Tab key to indent in short multi-line inputs in the interactive python.exe interpreter. Recently that stopped working - pressing the Tab key flashes the cursor and doesn't indent. Using spaces does work fine here, though it's not as convenient past a couple of indentations.
I suspect (but am not certain) that the cause was installation of pyreadline or rlcompleter - I had been messing with trying to get tab completion in an interpreter in an embedded application on Windows. Of course in your case another installation could have included those packages.

How can I stay tab-free in Geany on Ubuntu?

How can I stay tab free in Geany on Ubuntu?
When I am coding in Python, tabs have always annoyed me. And the TAB is invisible. So strange.
When I open my code by gedit, those TABs are visible.
You are looking for 'soft tabs'
http://www.geany.org/manual/dev/index.html#editor-indentation-preferences
Edit > Preferences > Editor > Indentation > Type > Spaces
After changing the setting, close and reopen the file.
To apply the tab settings to every document in the current session, also click:
Project->Apply Default.
DTing is right but on thing to remember:
You have to close all files (tabs) in Geany and open them up again to have the new settings work in each file. It took me days to figure out that I not only have to close geany and open it up again but that I also have to re-open each file seperately.
I know I'm a bit late on this, but hopefully this answer might help someone else. With Geany closed, edit ~/.config/geany/geany.conf with some other editor, changing the lines:
use_tab_to_indent=true
indent_type=1
to:
use_tab_to_indent=false
indent_type=0
and the settings will "take".
To take effect on opened documents has to go to:
Document-> indent_type -> spaces.
The document configuration has prevalence over the global.
Here's another tip I like that works in almost any editor. Enable view whitespace, and never get confused again about what's in the file:
Preferences > Editor > Display > ✔ Show Whitespace
Then restart Geany.
I use the the syntax highlighting features to make these symbols very subtle, a low contrast greyscale, so one has to look to see them. The tab is still somewhat easy to see in scintilla editors because it it will be a multi-character long arrow.
I faced the same problem, but documents opened as part of project.
In this case the tab/spaces setting is overriden by project->preferences

Categories

Resources