As you start acquiring more experience and start shifting from working on projects to working on products, you realize how much important it is for the code to be clean, understandable by others, and organized.
Here in this post, I'll explain, how you can work on the clean code part by setting up black on VSCode.
Firstly what is black? Black is the uncompromising Python code formatter , which helps you formatting your python files as per the pip8 style coding. You can read more about black here.
Now, let's start setting up black on our VSCode.
Installing black the env you're working on either the virtual env or local python, to do so you need to use the following command :
$ pip install black
Now make sure you have the Python extension installed in your VSCode.You can either do that by :
- Going to the Extensions tab and searching Python and installing the first one
- Accessing the quick open by "CTRL+P" and write the following command to install the extension :
ext install ms-python.python
- Now go to your VSCode settings by pressing "CTRL+," and make sure to do the following :
- Search
format on save
and make sure it's ticked/checked. - Search
python formatting
and make sure black is selected.
- Search
The settings after the above steps should look like this :
And Voila, you're all done. Now open any python file, work on it, and when you save the file it will automatically be formatted.
I hope this article helped you to make your code cleaner. Don't forget to comment with your valuable suggestions and feedback. In case you want to connect with me, follow the links below: