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

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:

Related

How to wrap lines automatically in Python Spyder?

I'm new to Python.
I'm using Spyder 4.0.1, Python 3.7.
The Spyder built-in PEP-8 convention code style check returns error E501 (line too long). Although I set the vertical line and wrap lines, it still shows error for the long characters line. Pycharm would wrap lines automatically, but I cannot find any effective solution in Spyder.
What should I do? Do I have to press Enter manually for the long line? Thanks.
In Windows Go To
Tools->Preferences->Editor and select Wrap lines.
If you use mac, you need to go to Python on the left right corner then click on Preferences.
Then go to Editor, and check Wrap lines.
To turn on the Word Wrap feature, go to View > Toggle Word Wrap or click the Edit Display icon in the Code Editor toolbar (it's the second-to-last one on the right) and select Toggle Word Wrap. You can also set the program preferences to keep this feature on by default.

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

Subsequent tabs being closed in pyqt

I am trying to close a tab when the users presses the close tab button. This is the code that should do that:
self.tab_widget.addTab(text, TabName)
self.tab_widget.setTabsClosable(1)
self.tab_widget.tabCloseRequested.connect(self.tab_widget.removeTab)
It works, but when I close a tab before other tab(s) it closes out all of them after it, and I am not sure why. Any help?
Oh... well I figured out why this was happening. I had the code that removes the tabs with the code that creates them and so I guess I was doing multiple connects thus getting rid of more than one tab.

PyDev adding tabs to block indentation

I am using Eclipse Ingigo with Pydev 2.3.0.2011121518, it has been working great, but has suddenly starting doing this weird thing with tabs.
I have got the "Replace tabs with spaces when typing" option set for PyDev --> Editor in Eclipse preferences, and that works fine, when I press tab, I get 4 spaces. However for some rerason, now when I create a block, such as an "if" block pydev automatically indents the next line, as it should but this time it adds a tab, leading to "Mixed Indentation: Tab found" warnings.
Has anyone seen this behavior before, and know a fix, or is it a bug with Pydev on Eclipse Indigo?
I have just solved this - I had the option ."Assume tab spacing when file contain tabs" checked in Eclipse Preferences --> PyDev --> Editor. When I unchecked this option the automatic indentation worked properly and it added spaces and not tabs. It seems that in one of my docstrings I had some tabs (possibly copied in from another editor), and that must have been making Eclipse assume tab spacing for automatic indentation (even though it was still replacing tabs with spaces as I typed them)
On mars2 and PyDev 5.1.1 this still occurs to me. I have Replace tabs with spaces when typing checked and Assume tab spacing when file contain tabs unchecked. I had to replace all tabs with spaces to remove this warning.
I've faced similar issue, for me the error was Mixed Indentation: Spaces found.
Solution: In Eclipse with Pydev, Source menu -> Convert tabs to space-tabs.

Categories

Resources