Pycharm配置autopep8實(shí)現(xiàn)流程解析
關(guān)于PEP 8
PEP 8,Style Guide forPythonCode,是Python官方推出編碼約定,主要是為了保證 Python 編碼的風(fēng)格一致,提高代碼的可讀性。
官網(wǎng)地址:https://www.python.org/dev/peps/pep-0008/
關(guān)于Autopep8
Autopep8是自動(dòng)將Python代碼格式化為符合PEP 8風(fēng)格的工具。它使用pycodestyle工具來確定代碼的哪些部分需要被格式化。Autopep8能夠修復(fù)大部分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」–>設(shè)置相關(guān)配置 -> 點(diǎn)擊加號(hào)添加工具
填寫如下配置項(xiàng),點(diǎn)擊「OK」保存
Settings–>Tools–>External Tools 點(diǎn)擊添加按鈕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自動(dòng)格式化你的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」即可

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python使用pandas導(dǎo)入xlsx格式的excel文件內(nèi)容操作代碼
這篇文章主要介紹了Python使用pandas導(dǎo)入xlsx格式的excel文件內(nèi)容,基本導(dǎo)入是在Python中使用pandas導(dǎo)入.xlsx文件的方法是read_excel(),本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
pandas如何將表中的字符串轉(zhuǎn)成數(shù)值型
在用pd.read_csv讀數(shù)據(jù)時(shí),將要轉(zhuǎn)換數(shù)據(jù)類型的列名和類型名構(gòu)成字典,傳給dtype,怎么轉(zhuǎn)換呢,下面小編給大家分享下pandas將表中的字符串轉(zhuǎn)成數(shù)值型,感興趣的朋友一起看看吧2023-02-02
Python實(shí)現(xiàn)為圖片添加水印的示例詳解
這篇文章主要介紹了如何通過Python3實(shí)現(xiàn)添加水印,這樣發(fā)朋友圈,圖片再也不怕被盜了?。?!文中的示例代碼簡潔易懂,需要的可以參考一下2022-02-02
詳解 Python 與文件對(duì)象共事的實(shí)例
這篇文章主要介紹了詳解 Python 與文件對(duì)象共事的實(shí)例的相關(guān)資料,希望通過本文大家能掌握這部分內(nèi)容,需要的朋友可以參考下2017-09-09
python使用正則表達(dá)式(Regular Expression)方法超詳細(xì)
這篇文章主要介紹了python使用正則表達(dá)式(Regular Expression)方法超詳細(xì),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Pandas如何通過np.array函數(shù)或tolist方法去掉數(shù)據(jù)中的index
這篇文章主要介紹了Pandas如何通過np.array函數(shù)或tolist方法去掉數(shù)據(jù)中的index問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02

