Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VS Code Python Formatter
#1
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
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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.
Reply
#4
(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.
Reply
#5
(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?
Reply
#6
(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.
Reply
#7
(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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use nb-black python cde formatter ErnestTBass 3 6,744 Jun-04-2020, 03:51 PM
Last Post: ErnestTBass

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020