麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Python > 正文

按PEP8風格自動排版Python代碼

2019-11-06 06:21:23
字體:
來源:轉載
供稿:網友

如果用編輯器寫代碼,很容易會怎么順手怎么來,而每個人的寫代碼習慣有很大不同,這樣會導致可讀性不是很好,代碼維護起來比較困難,當然各種編輯器一般都有各種用來自動排版的插件,例如Sublime Text就有:Python PEP8 Autoformat,使用方法:

默認快捷鍵:

Ctrl + Shift + R

不過,python的一些install腳本還是很強大的,例如python的autopep8庫: (鏈接:https://github.com/hhatto/autopep8)

$ pip install --upgrade autopep8

然后在命令行:

$ autopep8 --in-place --aggressive --aggressive <filename>

就可以對代碼進行pep8自動排版,對比了下效果,如下: 排版前

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 de 使用Sublime Text中的Python PEP8 Autoformat自動排版

import mathimport sysdef 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)

使用autopep8自動排版

import mathimport sysdef 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)

可以看到雖然都是PEP8風格,但是效果還是略有不同,可以根據需要個人習慣進行有選擇的使用。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 在线成人免费观看www | 亚州精品国产 | 亚洲第一男人天堂 | 深夜影院一级毛片 | 亚洲午夜天堂吃瓜在线 | 久久久久久久久久美女 | 精品国产一区二区三区久久久 | 看av网址| 欧美在线观看视频一区 | av成人在线电影 | 久草在线手机观看 | 日本va在线观看 | v片在线看 | 性欧美极品xxxx欧美一区二区 | 久久久久久久久久美女 | 视频www| 成年人视频在线免费播放 | 国产美女爽到喷白浆的 | 国产成人高潮免费观看精品 | 懂色av懂色aⅴ精彩av | 久久久久久久一区二区 | 在线无码| 国产成人av一区二区 | 国产91小视频在线观看 | 国产精品久久久麻豆 | 日韩在线播放一区二区 | 久久午夜神器 | 在线看免费观看av | www.91成人| 久久撸视频 | 成人福利网| 久草在线视频在线 | 草逼一区 | 免费国产一级淫片 | 久久精品伊人网 | 久久久久久久不卡 | 91精品国产一区二区在线观看 | 爱草成年 | 久久蜜桃香蕉精品一区二区三区 | aa国产视频一区二区 | 国产精品视频在 |