亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python Autopep8實(shí)現(xiàn)按PEP8風(fēng)格自動(dòng)排版Python代碼

瀏覽:26日期:2022-06-26 15:46:59

Autopep8是一個(gè)將Python代碼自動(dòng)排版為PEP8風(fēng)格的小工具。它使用pep8工具來(lái)決定代碼中的哪部分需要被排版。Autopep8可以修復(fù)大部分pep8工具中報(bào)告的排版問(wèn)題。

參考網(wǎng)址:

https://www.python.org/dev/peps/pep-0008/

https://pypi.python.org/pypi/autopep8/

(1)安裝步驟如下:

localhost:~ a6$ sudo pip install autopep8Password:The directory ’/Users/a6/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.The directory ’/Users/a6/Library/Caches/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.Collecting autopep8Collecting pycodestyle>=2.3 (from autopep8) Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB) 100% |????????????????????????????????| 51kB 324kB/sInstalling collected packages: pycodestyle, autopep8Successfully installed autopep8-1.3.3 pycodestyle-2.3.1localhost:~ a6$ sudo pip install autopep8The directory ’/Users/a6/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.The directory ’/Users/a6/Library/Caches/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.Requirement already satisfied: autopep8 in /Library/Python/2.7/site-packagesRequirement already satisfied: pycodestyle>=2.3 in /Library/Python/2.7/site-packages (from autopep8)

(2)示例代碼:

1)運(yùn)行命令前代碼的排版 (保存在test_autopep8.py)

import math, sys; def example1(): ####This is a long comment. This should be wrapped to fit within 72 characters. 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 {’has_key() is deprecated’:True}.has_key({’f’:2}.has_key(’’));class Example3( object ): def __init__ ( self, bar ): #Comments should have a space after the hash. if bar : bar+=1; bar=bar* bar ; return bar else: some_string = ''' Indentation in multiline strings should not be touched.Only actual code should be reindented.''' return (sys.path, some_string)

2)運(yùn)行命令

bogon:AB a6$ autopep8 --in-place --aggressive --aggressive test_autopep8.py

3)運(yùn)行命令后代碼的排版

import mathimport sys def example1(): # This is a long comment. This should be wrapped to fit within 72 # characters. 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 return bar else: some_string = ''' Indentation in multiline strings should not be touched. Only actual code should be reindented. ''' return (sys.path, some_string)

4)參考網(wǎng)址:https://github.com/hhatto/autopep8

到此這篇關(guān)于python Autopep8實(shí)現(xiàn)按PEP8風(fēng)格自動(dòng)排版Python代碼的文章就介紹到這了,更多相關(guān)python Autopep8自動(dòng)排版內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品国产美女在线观看 | 亚洲精品视频在线 | 国产一级α片 | 美国美女一级片 | 涩色婷婷狠狠第四四房社区奇米 | 亚洲成人一区二区 | 1769视频在线观看国产 | www.成人网.com| 免费观看毛片 | 成人18免费网站在线观看 | 欧美一级毛片aaaaa | 国产成人精品三区 | 快射影院 | 黄色片网站大全 | 欧美在线观看一区二区 | 国产成人mv免费视频 | 精品欧美一区二区vr在线观看 | 朴妮唛1一30集福利在线播放 | 国产欧美一区二区精品性色 | 欧美一区二区在线免费观看 | 在线精品亚洲 | 在线伊人 | 国产精品真实对白精彩久久 | 日本限制级在线 | 亚洲第一视频网站 | 亚洲欧美日韩在线精品一区二区 | 自拍视频网 | 色老成人精品视频在线观看 | 国产一区免费在线观看 | 国产高清不卡一区二区三区 | 中文免费观看视频网站 | 在线免费看黄视频 | 亚洲精品久久久久久久777 | 免费观看欧美一区二区三区 | www久久com| 色综合久久亚洲国产日韩 | 亚洲欧美国产日本 | 国产高清视频免费在线观看 | 欧美日韩国产免费一区二区三区 | 国产一区二区免费福利片 | 九九免费精品视频在这里 |