![]() ![]() You can also format your code by right clicking somewhere in the code and then clicking to " Format Document", this action is equivalent to CTRL + SHIFT + I. Now all you have to do is save a python file by pressing CTRL + S and the black formatter will format your code.įor example, this is how a unformatted code looks like To enable this option, go to settings and search for "editor.formatOnSave" and check the box as shown in the image below If you want your code to be automatically formatted once you save your code by pressing CTRL + S, you can do so by enabling the format on save option. Now your vscode is using black formatter to format code Once you are in the settings section, click to the search box and type and the option "Python Formatting Provider" should show up as shown in the image belowĬlick to the drop down box, and select "black" Go to Settings by pressing CTRL + comma, or by GUI: File > Preferences > Settingsģ. Once you have installed black formatter on your computer, now you need to configure it so you can use it.Ģ. Press CTRL + P on vscode and enter the command below ext install ms-python.black-formatter Next, Install the extension by clicking the "Install" button Install black formatter from vscode extensionsĪlternatively, you can install black formatter from extension section on visual studio code, press CTRL + SHIFT + X to open the extension window, and search for "Black formatter" and click it Install black formatter via pip pip install black There are multiple ways to install black formatter extension, In this tutorial, you will learn how to format python on Vscode.īlack formattter is the extension that we are going to use to format the code on visual studio code. ![]() You may think, I can read it because I wrote it, that's true but not always, especially when working on your old projects. Formatting your code it's a must when it comes to coding, because not only it makes it look better and clean, but it also saves you a lot of time because it's easier to read it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |