I paste code in a jupyter notebook. The hidden characters from text editor are copied. How to disable this? - python

I am using Jupyter Notebook with the Python 3 ipykernel. If I paste code from a text editor into the Jupyter Notebook, all the hidden characters (in the text editor) show up as visible characters.
It is strange: e.g., I can backspace and erase the space hidden character, then hit space and it does not reappear.
What is happening and how do I disable it?
I tried to paste the character here, but they disappear. Here is an image for reference:
To resolve this issue, I use crtl+a, tab, shift+tab, and the hidden characters disappear. I am use Sublime 3 as a text editor, but if I open gedit, and I type exactly what is displayed in the image and paste in Jupyter Notebooks, I still see the hidden characters. This issue is new (e.g., it wasn't occurring just a week ago).

I am use Sublime 3 as a text editor
Your complaint boils down to "my text editor is indenting with TAB character rather than with four SPACE characters".
You can verify that diagnosis with tail my_source_code.py | hexdump -C
and notice the 0x09 (decimal nine) TAB characters instead
of 0x20 (decimal 32) SPACE characters.
Visit the Preferences screen in your editor
and ask it to use SPACE instead of TAB.

Related

Why does VSCode Python always put two tabs instead of one?

In my VSCode settings, I have Tab Size set to 2 and in Prettier I have it set to 2 spaces as well. It works fine, whenever I go to the next line, it indents by 1 tab (2 spaces) and whenever I press tab it places a tab where my cursor was. But when I save my file, all of the single tabs for indenting turn into 2 tabs. Here is an image from after saving: image. And yes, I am making a Discord Bot.
I saved my file and I expected it to look like this
I want to indent using tabs but when I save it indents with 2 tabs and that's annoying
Click the Select Indentation option in the lower right corner.
Choose Indent Using Tabs
Choose 2.
You can also change the settings by searching tab size:

How to see variables denoted by Greek letters in viscode's interactive window?

I'm currently using Python3.73 on VSCode. I execute the code on interactive window with Jupiter notebook. The problems are:
I can't type Greek letters in notebook cells while I can type them in editor using LaTeX syntax;
Even if I copy a Greek letter from somewhere else and paste it in a cell in interactive window and denote it as the name of a variable, I can't find this variable in the interactive data viewer. But I'm sure it's stored somewhere because I can still call it again.
e.g.
example code
, but the eigenvalues can't be seen after clicking the
"Show variable in data viewer button"
So how can I type Greek letters in interactive cells directly? and how can I see variables denoted by Greek letters?
how can I type Greek letters in interactive cells directly?
Jupyter Notebook can recognize Greek letters, after typing \alpha, pressing Tab, you'll get α, which you can try in JupyterLab. But it's not achievable in VS Code.
Although Greek letters' English name are stored in Jupyter in VS Code, but it couldn't be turned into α automatically in VS Code. Furthermore, to Tab Complete Greek Letters, the production group vscode-jupyter does't have plans on adding this functionality at this time.
how can I see variables denoted by Greek letters?
The default encoding format is UTF-8. Not only Greek, but also Cyllic and other non-english language can't be shown in Variables Viewer. So there's no way to do that.
I was also missing this feature from vscode. Luckily, there is now the tablatex extension, that does exactly what you want:
https://marketplace.visualstudio.com/items?itemName=andyljones.tablatex

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?
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.

Show indents for Spyder IDE

Is there a way to visualize tab indents in the Spyder?
I know I can visualize blank spaces under the 'Source' tab. For tabs, this now shows 4 dots.
It would be great if there was a way to show this as a single tab rather than 4 spaces.
I'm pretty sure there are actually 4 spaces there. As per PEP8, Python code should use 4 spaces for indentation, not a tab character. If you haven't changed your settings* in Spyder, it will insert 4 spaces when you press the tab key.
Spyder 4 will allow you to mark indentation levels with vertical lines. It will hopefully be released in 2019. Or you can already download the first beta.
*The characters used for indentation could be changed by going to Tools/Preferences/Editor/Indentation characters. It should always be 4 spaces though.

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

Categories

Resources