pythonsortingvisual-studio-codeimportisort

VSCode: how to config 'Organize imports' for Python (isort)


Mirror question to:

I want to configure how VSCode is invoking isort, so I can customize when calling Organize imports in a .py file.


In particular, VSCode has started removing a blank line between two isort-sections, don't know why.

from django...
from myproject... # removing blanck line between 2 sections

Solution

  • In VS Code, the "Python" extension provides us with the following settings, which can merge specific imports from the same module into a single import statement, and organize the import statements in alphabetical order. (in "settings.json" file)

    "python.sortImports.args": ["-rc", "--atomic"],
    

    For using "Sort Imports" in VS Code, please refer to this document: Sort Imports in VS Code.