Visual Studio Code with Python auto-formatting
I was writing python code and facing issues with formatting. It becomes a problem with code review and toolings to detect these issues. Life is much easier with formatter integrated with your code editor and auto-fix those issues on save. Here is how to do:
-
First, install yapf from Google as a formatter:
pip install yapf
-
Next, in your Visual Studio Code editor, press “Command + Shift + P” for mac for “Ctrl + Shift + P” for linux, and type to search “Open settings (JSON) and add this lin
“python.formatting.provider”: “yapf”
-
If you want to auto format on save instead of just tips in editor, add this setting as well:
“editor.formatOnSave”: true
-
Optionally, if you want to use your project .styles.yapf instead of global styles, add this line as well:
“python.formatting.yapfArgs”: [ “–style”, “.style.yapf” ]
Now you can test it out, such as not having a new line at the end of the python file, then press saves, it would fix your new line issue automatically for you.

About
Software development professional with expertise in application architecture, cloud solutions deployment, and financial products development. Possess a Master's degree in Computer Science and an MBA in Finance. Highly skilled in AWS (Certified Solutions Architect, Developer and SysOps Administrator), GCP (Professional Cloud Architect), Microsoft Azure, Kubernetes(CKA, CKAD, CKS, KCNA), and Scrum(PSM, PSPO) methodologies.