Pycharm配置autopep8實現(xiàn)流程解析
關于PEP 8
PEP 8,Style Guide forPythonCode,是Python官方推出編碼約定,主要是為了保證 Python 編碼的風格一致,提高代碼的可讀性。
官網(wǎng)地址:https://www.python.org/dev/peps/pep-0008/
關于Autopep8
Autopep8是自動將Python代碼格式化為符合PEP 8風格的工具。它使用pycodestyle工具來確定代碼的哪些部分需要被格式化。Autopep8能夠修復大部分pycodestyle檢測的格式問題。
github地址:https://github.com/hhatto/autopep8
下載安裝Autopep8
pip install autopep8
使用Autopep8
命令行使用方式如下
$ autopep8 --in-place --aggressive --aggressive <filename>
$ autopep8 --in-place --aggressive --aggressive Student.py
Pycharm配置Autopep8方法
1)具體流程:選擇菜單「File」–>「Settings」–>「Tools」–>「External Tools」–>設置相關配置 -> 點擊加號添加工具
填寫如下配置項,點擊「OK」保存
Settings–>Tools–>External Tools 點擊添加按鈕Name:autopep8(可以自定義)
Tools settings:
Programs:autopep8(不能修改)
Parameters:--in-place --aggressive --aggressive $FilePath$
Working directory:$ProjectFileDir$
Advanced Options:在output filters添加:$FILE_PATH$\:$LINE$\:$COLUMN$\:.*
3) 使用autopep8自動格式化你的python代碼
import math def example1(): some_tuple = (1, 2, 3, 'a') some_variable = { 'long': 'Long code lines should be wrapped within 79 characters.', 'other': [math.pi, 100, 200, 300, 9876543210,'This is a long string that goes on'], 'more': { 'inner': 'This whole logical line should be wrapped.',some_tuple: [ 1,20, 300, 40000,500000000,60000000000000000]}} return (some_tuple, some_variable) def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True}; class Example3(object): def __init__(self, bar): # Comments should have a space after the hash. if bar: bar += 1 bar = bar * bar else: some_string = """ Indentation in multiline strings should not be touched.Only actual code should be reindented. """
第一種方式:
編寫完代碼后,右鍵選擇「Extern Tools」–>「autopep8」
第二種方式:
選擇菜單「Tool」–>「Extern Tools」–>「autopep8」即可
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
如何使用Python的Requests包實現(xiàn)模擬登陸
這篇文章主要為大家詳細介紹了使用Python的Requests包模擬登陸,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04Python Flask實現(xiàn)圖片驗證碼與郵箱驗證碼流程詳細講解
這篇文章主要介紹了如何利用Python生成隨機的圖片驗證碼與郵箱驗證碼,驗證碼是一種區(qū)分用戶是計算機還是人的公共全自動程序,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起試試2022-10-10初次部署django+gunicorn+nginx的方法步驟
這篇文章主要介紹了初次部署django+gunicorn+nginx的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09