isort 格式化 python import 的區塊

Posted in :

有一天我在看 selenium 的 commit log 時, 發現改版內容裡寫了 isort 來排序, 並把單行多個 import 換成單行單一import, 傳送門:
https://github.com/SeleniumHQ/selenium/commit/3167e93110f70937ddec6bfbfce87ccef03c4f30

isort 其實就是一個 formatter,同時也是命令列工具,類似 yapf、Black,但它只負責和 import 有關的格式化, 官方的 github:
https://github.com/PyCQA/isort

Installing isort

Installing isort is as simple as:

pip install isort

Using isort

From the command line:

To run on specific files:

isort mypythonfile.py mypythonfile2.py

To apply recursively:

isort .

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *