How to setup VS Code for formatting line breaking symmetrically for Python?

299 views Asked by At

Original code

            job.create_common_job_log_line(message=message, model_id=model_id, product_id=product.id)

This is how it formatted my code which is extremely ugly

            job.create_common_job_log_line(
                message=message, model_id=model_id, product_id=product.id)

I expect

            job.create_common_job_log_line(
                message=message, model_id=model_id, product_id=product.id
            )

or

            job.create_common_job_log_line(
                message=message, 
                model_id=model_id, 
                product_id=product.id
            )
1

There are 1 answers

0
Jill Cheng On

Please use the formatting provided by "black" in settings.json file: (VS Code uses 'autopep8' for formatting by default.)

 "python.formatting.provider": "black",
 "editor.formatOnSave": true,

enter image description here

Reference: Formatting in Vs Code.