久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

python Autopep8實現按PEP8風格自動排版Python代碼

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

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

參考網址:

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)參考網址:https://github.com/hhatto/autopep8

到此這篇關于python Autopep8實現按PEP8風格自動排版Python代碼的文章就介紹到這了,更多相關python Autopep8自動排版內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产中文字幕在线观看 | 奇米色777欧美一区二区 | 欧美一级久久 | 亚洲激情欧美 | 久久夫妻网 | 一级黄色录像视频 | 午夜窝窝 | 欧美黄色一级毛片 | www.久草.com| 国产精品久久久久久久久费观看 | 成人爽a毛片一区二区免费 美女高潮久久久 | 日韩理伦在线 | 91免费国产| 亚洲一区 | 国产女爽爽视频精品免费 | 电影午夜精品一区二区三区 | 久久伊人草 | 午夜免费电影 | 一级片在线观看 | 亚洲午夜一区 | 久草在线 | 欧美韩日 | 亚洲永久免费视频 | 国产精品一区免费在线观看 | 国产一区二区三区 | 亚洲精品国精品久久99热 | 色.com| 狠狠躁日日躁夜夜躁东南亚 | 男人天堂网站 | 亚洲成人在线网站 | 高清视频一区二区三区 | 亚洲不卡在线 | 99福利视频 | 免费在线成人 | 日韩在线一区二区 | 亚洲精品乱码久久久久久蜜桃图片 | 男女做爰高清无遮挡免费视频 | 国产人成精品一区二区三 | 两性午夜视频 | 国产精品视频在线观看 | 免费视频爱爱太爽了 |