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

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

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

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

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

到此這篇關于python Autopep8實現(xiàn)按PEP8風格自動排版Python代碼的文章就介紹到這了,更多相關python Autopep8自動排版內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    python Tornado框架的使用示例

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

    通過代碼實例了解Python sys模塊

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

最新評論

湖口县| 孝昌县| 德兴市| 华容县| 广东省| 固镇县| 蓬溪县| 绍兴市| 德钦县| 井陉县| 余干县| 奉节县| 阳曲县| 濉溪县| 勐海县| 华亭县| 从江县| 汉沽区| 兰坪| 新化县| 曲周县| 巨野县| 青海省| 宝清县| 江永县| 兴城市| 湘西| 密山市| 金坛市| 图木舒克市| 从化市| 深圳市| 慈溪市| 蒲城县| 涟水县| 稻城县| 胶南市| 德兴市| 金川县| 绥芬河市| 恩平市|