Pycharm配置autopep8教程,讓Python代碼更符合pep8規範

來源:互聯網
上載者:User

標籤:python pep8

一、何為pep8?
  • PEP 8官方文檔 -- Style Guide for Python Code

  • PEP8中文翻譯(轉)

二、Pycharm中配置pep8

Pycharm本身是有pep8風格檢測的,當你敲得代碼中不符合規範時,會有下劃波浪線提示。如何讓代碼修改為符合規範,去掉這些難看的波浪線呢?下面介紹步驟:

2.1安裝autopep8

cmd視窗輸入:pip install autopep8

2.2在Pycharm中安裝autopep8配置
  • Tools→Extends Tools→點擊加號

  • 650) this.width=650;" src="https://segmentfault.com/img/bVyzil" style="border:1px solid rgb(221,221,221);vertical-align:middle;padding:3px;" alt="bVyzil" />

  • 配置項

650) this.width=650;" src="https://segmentfault.com/img/bVyzik" style="border:1px solid rgb(221,221,221);vertical-align:middle;padding:3px;" alt="bVyzik" />

  • Name:Autopep8(可以隨便取)

  • Tools settings:

    • Programs:autopep8 (前提是你已經安裝了哦)

    • Parameters:--in-place --aggressive --aggressive $FilePath$

    • Working directory:$ProjectFileDir$

  • 點擊Output Files→添加,在對話方塊中的:Regular expression to match output中輸入:$FILE_PATH$\:$LINE$\:$COLUMN$\:.*

autopep8在pycharm中的使用:在Pycharm編輯其中建立一個python檔案,編輯一些不符合pep8風格的代碼;將滑鼠放在該檔案的編輯器中→右鍵→External Tools→點擊Autopep8。這樣你的代碼就符合pep8的風格了。如所示
650) this.width=650;" src="https://segmentfault.com/img/bVyzjq" style="border:1px solid rgb(221,221,221);vertical-align:middle;padding:3px;color:rgb(51,51,51);font-family:‘Helvetica Neue‘, Helvetica, Arial, ‘PingFang SC‘, ‘Hiragino Sans GB‘, ‘WenQuanYi Micro Hei‘, ‘Microsoft Yahei‘, sans-serif;font-size:14px;white-space:normal;background-color:rgb(255,255,255);" alt="bVyzjq" />

本文出自 “TCollaboration” 部落格,請務必保留此出處http://tcollaboration.blog.51cto.com/6328404/1875663

Pycharm配置autopep8教程,讓Python代碼更符合pep8規範

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.