I have VSCode installed and python 3.6.8 I use tabs for my indentation. But when ever I save the file, all the tabs are being converted to spaces. This might be because of the formatter I use, i.e. Black. How do I prevent the formatter from doing that(Do all your formatting except inter-changing indents with spaces)?
Thank you
Tabs are the most common problem, some code editors will treat each tab indent as very small, where as others will treat it like a huge block. This leads to not all code indentation looking the same across multiple developers systems. With spaces you do not have this translation problem, a space, is always just 1 space.
So if you’re using tab indentation, you will have to convert the imported libraries to tabs. If you’re a Sublime Text user you can add these rules to your Preferences.sublime-settings file to ensure tabs get converted to spaces and also use 2 spaces as a default indentation level:
However, it’s important you use the same method as the rest of your development team (or try and get them to change ;)), consistency is the real best answer. So if that means using tabs, then so be it. But why? The way in which you indent your code may seem trivial, and for the most part it usually is.
Indent changes automatically when bullet number 10 is reached. - Microsoft Community Indent changes automatically when bullet number 10 is reached. Hi there. Have a look at the picture below... When I use bullets/numbering, the space between the numbering and the actual paragraph changes.
Not only 'black' but also 'autopep8' and 'yapf' will convert the tabs to spaces. And looks like both 'black', 'autopep8' and 'yapf' haven't provided args to change the format behavior of indent. And I agree with Brett Cannon, you'd better adapt to space indent.
If you really want a try of that, you can find the black.py in site-packages folder and at the lines of 1540 in black.py change the ' '(four spaces) to ' '(a tab, copy a tab, and you can choose any spaces of the tab contains). Then you can get what you want. But, I really don't recommend it.
Both autopep8
and black
are very strict.
They don't just recommend spaces over tabs, but force the usage of space indentation.
If you really want to use tabs, you should use yapf
, with style use_tabs=True
.
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