亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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編寫繪圖系統(tǒng)之從文本文件導(dǎo)入數(shù)據(jù)并繪圖

    Python編寫繪圖系統(tǒng)之從文本文件導(dǎo)入數(shù)據(jù)并繪圖

    這篇文章主要為大家詳細(xì)介紹了Python如何編寫一個(gè)繪圖系統(tǒng),可以實(shí)現(xiàn)從文本文件導(dǎo)入數(shù)據(jù)并繪圖,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2023-08-08
  • Python爬取365好書中小說代碼實(shí)例

    Python爬取365好書中小說代碼實(shí)例

    這篇文章主要介紹了Python爬取365好書中小說代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Windows上安裝tensorflow  詳細(xì)教程(圖文詳解)

    Windows上安裝tensorflow 詳細(xì)教程(圖文詳解)

    這篇文章主要介紹了Windows上安裝TENSORFLOW 詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • python中的函數(shù)遞歸和迭代原理解析

    python中的函數(shù)遞歸和迭代原理解析

    這篇文章主要介紹了python中的函數(shù)遞歸和迭代原理解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 一文帶你了解python中的多態(tài)性

    一文帶你了解python中的多態(tài)性

    多態(tài)性是 OOP 的一個(gè)特征,這意味著一個(gè)名稱可以具有不同的功能, 這篇文章主要為大家詳細(xì)介紹了如何在 Python 中實(shí)現(xiàn)多態(tài)性,感興趣的小伙伴可以學(xué)習(xí)一下
    2023-11-11
  • Python的形參和實(shí)參使用方式

    Python的形參和實(shí)參使用方式

    今天小編就為大家分享一篇Python的形參和實(shí)參使用方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python 專題二 條件語句和循環(huán)語句的基礎(chǔ)知識

    Python 專題二 條件語句和循環(huán)語句的基礎(chǔ)知識

    本文主要介紹了Python條件語句和循環(huán)語句的基礎(chǔ)知識。主要內(nèi)容包括: 1.條件語句:包括單分支、雙分支和多分支語句,if-elif-else;2.循環(huán)語句:while的使用及簡單網(wǎng)絡(luò)刷博器爬蟲;3.循環(huán)語句:for的使用及遍歷列表、元組、文件和字符串。
    2017-03-03
  • 解決Python print輸出不換行沒空格的問題

    解決Python print輸出不換行沒空格的問題

    今天小編就為大家分享一篇解決Python print輸出不換行沒空格的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • Python腳本實(shí)現(xiàn)代碼行數(shù)統(tǒng)計(jì)代碼分享

    Python腳本實(shí)現(xiàn)代碼行數(shù)統(tǒng)計(jì)代碼分享

    這篇文章主要介紹了Python腳本實(shí)現(xiàn)代碼行數(shù)統(tǒng)計(jì)代碼分享,本文給出了實(shí)現(xiàn)代碼和使用方法及統(tǒng)計(jì)效果,需要的朋友可以參考下
    2015-03-03
  • python調(diào)用有道智云API實(shí)現(xiàn)文件批量翻譯

    python調(diào)用有道智云API實(shí)現(xiàn)文件批量翻譯

    這篇文章主要介紹了python如何調(diào)用有道智云API實(shí)現(xiàn)文件批量翻譯,幫助大家更好得理解和使用python,感興趣的朋友可以了解下
    2020-10-10

最新評論