Python Forum

Full Version: VS Code Python Formatter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings,

I use VS Code for Python and other languages. However, I cannot find a good source formatter extension for Python. I've tried black, autopep8 and they work ok but they do not fix tab indentation errors.

Does anyone know if there are ways to configure these extension, mainly; autopep8?

Thanks,
Matt
Just don't use tabs: https://www.python.org/dev/peps/pep-0008...-or-spaces


If you use tabs, you've to use them everywhere. Mixing tabs and whitespace ends in a IndentationError which means also, that these tools could not parse the code.

It's not the fault of black or autopep8.
I know, and get that. However, if something is slightly indented and gives me an error; I was hoping one of these extensions would fix the indentation error.
How many spaces do you use?



(Sep-06-2021, 02:56 PM)DeaD_EyE Wrote: [ -> ]Just don't use tabs: https://www.python.org/dev/peps/pep-0008...-or-spaces


If you use tabs, you've to use them everywhere. Mixing tabs and whitespace ends in a IndentationError which means also, that these tools could not parse the code.

It's not the fault of black or autopep8.
(Sep-06-2021, 02:59 PM)muzikman Wrote: [ -> ]I know, and get that. However, if something is slightly indented and gives me an error; I was hoping one of these extensions would fix the indentation error.
How many spaces do you use?
Yes it will fix indentation and other stuff,setting is in python.formatting.provider
I have set it to black.
Also talk about here in my tutorial.
(Sep-06-2021, 04:22 PM)snippsat Wrote: [ -> ]
(Sep-06-2021, 02:59 PM)muzikman Wrote: [ -> ]I know, and get that. However, if something is slightly indented and gives me an error; I was hoping one of these extensions would fix the indentation error.
How many spaces do you use?
Yes it will fix indentation and other stuff,setting is in python.formatting.provider
I have set it to black.
Also talk about here in my tutorial.

I have that set as black in my settings. It will format the long dictionaries, etc. But it's not fixing the indents as it did in your example.

And, every time I paste some code, black says, "Cannot be used with the format selection command"

I checked over the tutorial and made sure I had all of the packages installed for my conda environment.

Is there a config for black?
(Sep-06-2021, 05:11 PM)muzikman Wrote: [ -> ]black says, "Cannot be used with the format selection command"
I have not gotten that message.
Look like can just turn it off.
(Sep-06-2021, 02:59 PM)muzikman Wrote: [ -> ]How many spaces do you use?

I use 0 spaces.

My IDE (PyCharm) indents by 4 Spaces (PEP8) if I press the tabulator key.
Just use an IDE. PyCharm has also a 3rd party Plugin called BlackConnect.
This requires a running black[d] instance.