最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2021年03月02日 11:34:27   作者:Data_IT_Farmer  
這篇文章主要介紹了python Autopep8實(shí)現(xiàn)按PEP8風(fēng)格自動(dòng)排版Python代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

參考網(wǎng)址:

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

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

(1)安裝步驟如下:

localhost:~ a6$ sudo pip install autopep8
Password:
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 autopep8
Collecting pycodestyle>=2.3 (from autopep8)
 Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB)
  100% |████████████████████████████████| 51kB 324kB/s
Installing collected packages: pycodestyle, autopep8
Successfully installed autopep8-1.3.3 pycodestyle-2.3.1
localhost:~ a6$ sudo pip install autopep8
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.
Requirement already satisfied: autopep8 in /Library/Python/2.7/site-packages
Requirement 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 math
import 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python?eval()和exec()函數(shù)使用詳解

    Python?eval()和exec()函數(shù)使用詳解

    exec函數(shù)執(zhí)行的是python語句,沒有返回值,eval函數(shù)執(zhí)行的是python表達(dá)式,有返回值,exec函數(shù)和eval函數(shù)都可以傳入命名空間作為參數(shù),本文給大家介紹下Python?eval()和exec()函數(shù),感興趣的朋友跟隨小編一起看看吧
    2022-11-11
  • Python對字符串實(shí)現(xiàn)去重操作的方法示例

    Python對字符串實(shí)現(xiàn)去重操作的方法示例

    字符串去重是python中字符串操作常見的一個(gè)需求,最近在工作中就又遇到了,所以下面這篇文章主要給大家介紹了關(guān)于Python對字符串實(shí)現(xiàn)去重操作的相關(guān)資料,文中給出了詳細(xì)的介紹,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • Python使用三種方法實(shí)現(xiàn)PCA算法

    Python使用三種方法實(shí)現(xiàn)PCA算法

    這篇文章主要介紹了Python使用三種方法實(shí)現(xiàn)PCA算法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • python字符串過濾性能比較5種方法

    python字符串過濾性能比較5種方法

    這篇文章主要介紹了python字符串過濾性能比較5種方法的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • python PyQt5 爬蟲實(shí)現(xiàn)代碼

    python PyQt5 爬蟲實(shí)現(xiàn)代碼

    這篇文章主要介紹了python PyQt5 爬蟲實(shí)現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Django中使用 Closure Table 儲(chǔ)存無限分級數(shù)據(jù)

    Django中使用 Closure Table 儲(chǔ)存無限分級數(shù)據(jù)

    對于數(shù)據(jù)量大的情況(比如用戶之間有邀請鏈,有點(diǎn)三級分銷的意思),就要用到 closure table 的結(jié)構(gòu)來進(jìn)行存儲(chǔ)。這篇文章主要介紹了Django中使用 Closure Table 儲(chǔ)存無限分級數(shù)據(jù),需要的朋友可以參考下
    2019-06-06
  • 利用Python統(tǒng)計(jì)Jira數(shù)據(jù)并可視化

    利用Python統(tǒng)計(jì)Jira數(shù)據(jù)并可視化

    目前公司使用 Jira 作為項(xiàng)目管理工具,在每一次迭代完成后的復(fù)盤會(huì)上,我們都需要針對本次迭代的 Bug 進(jìn)行數(shù)據(jù)統(tǒng)計(jì),以幫助管理層能更直觀的了解研發(fā)的代碼質(zhì)量。本篇文章將介紹如何利用統(tǒng)計(jì) Jira 數(shù)據(jù),并進(jìn)行可視化,需要的可以參考一下
    2022-07-07
  • python實(shí)現(xiàn)定時(shí)播放mp3

    python實(shí)現(xiàn)定時(shí)播放mp3

    這篇文章主要介紹了python實(shí)現(xiàn)定時(shí)播放mp3,程序非常簡單,功能很實(shí)用,主要是使用python實(shí)現(xiàn)了一首mp3歌每半小時(shí)播放一次,有需要的小伙伴可以參考下。
    2015-03-03
  • python Tornado框架的使用示例

    python Tornado框架的使用示例

    這篇文章主要介紹了python Tornado框架的使用示例,幫助大家更好的利用python進(jìn)行web開發(fā),感興趣的朋友可以了解下
    2020-10-10
  • 通過代碼實(shí)例了解Python sys模塊

    通過代碼實(shí)例了解Python sys模塊

    這篇文章主要介紹了通過代碼實(shí)例了解Python sys模塊,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09

最新評論

嘉义县| 奉新县| 龙里县| 江永县| 五家渠市| 万全县| 洛浦县| 平邑县| 曲靖市| 石棉县| 宜良县| 贺兰县| 新邵县| 鲁山县| 开阳县| 安宁市| 甘洛县| 西和县| 宁德市| 康平县| 马边| 石首市| 镇宁| 兴仁县| 大关县| 山东省| 克拉玛依市| 阿拉善左旗| 汪清县| 莎车县| 托里县| 高台县| 平安县| 札达县| 黄山市| 沾益县| 嘉兴市| 宣恩县| 宁夏| 松原市| 保亭|