Try   HackMD

Python Auto formatting on VSCode

  1. 首先至開啟 Windows 的 CMD、PowerShell 或者是 windows Terminal,如果是使用 MacBook 則開啟終端機,輸入 pip install yapf,下載 yapf 格式化工具。
    如果電腦中已存在 yapf 格式化工具,就會出現類似如下圖內容的訊息。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    如果之前沒有下載過,則可能出現類似下圖內容。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  2. 首先開啟 VSCode,並找到右下角的設定圖示。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  3. 點擊後,選擇 Settings 選項。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  4. 進入 Settings 畫面後,在上方的搜尋列中,輸入 python.formatting.provider,便會出現可以調整自動排版的工具選項,此處選擇 yapf

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  5. 接著清空上方搜尋列,輸入 format on save,並找到對應控制項目,確認確實勾選起來。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →