色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

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

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

參考網(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)運行命令前代碼的排版 (保存在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)運行命令

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

3)運行命令后代碼的排版

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 成人综合婷婷国产精品久久免费 | 一色屋成人免费精品网站 | 亚洲国产成人精品久久 | 99久久精品久久久久久婷婷 | 国产精品一区久久精品 | 免费香蕉成视频成人网 | 在线 中文字幕 日韩 欧美 | 99热r| 美女被cao免费看在线看网站 | 尹人香蕉久久99天天拍 | 亚洲国产午夜精品理论片的软件 | 免费a级毛片大学生免费观看 | a级毛片毛片免费观看永久 a级毛片毛片免费很很综合 | 亚洲综合一区二区精品久久 | 亚洲精品一二三区-久久 | 久久精品a一国产成人免费网站 | 日本三本道 | 亚洲日本欧美产综合在线 | 99精品高清视频一区二区 | 美女张开腿让男人桶的动态图 | 亚洲精品午夜久久久伊人 | 一级毛片q片 | 欧美亚洲一级片 | 日韩一区二区久久久久久 | 亚洲欧洲无码一区二区三区 | 国产成人免费高清激情视频 | 私人毛片免费高清影视院丶 | 久草视频手机在线 | 99久久综合给久久精品 | 国产www| 天天夜夜久久 | 亚洲国产人成中文幕一级二级 | 在线播放一区二区精品产 | 欧美成人一区二区三区 | 欧美日韩精品在线视频 | 国产成人lu在线视频 | 99在线免费观看 | 72种姿势欧美久久久久大黄蕉 | 久久国产毛片 | 91精品免费高清在线 | 亚洲男人的天堂久久无 |