校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > Autopep8的使用(python自動編排工具)

Autopep8的使用(python自動編排工具)

熱門標簽:電銷機器人系統(tǒng)廠家鄭州 遼寧智能外呼系統(tǒng)需要多少錢 400電話申請資格 舉辦過冬奧會的城市地圖標注 qt百度地圖標注 地圖地圖標注有嘆號 螳螂科技外呼系統(tǒng)怎么用 阿里電話機器人對話 正安縣地圖標注app

什么是Autopep8

在python開發(fā)中, 大家都知道,python編碼規(guī)范是PEP8,但是在市級開發(fā)中有的公司嚴格要求PEP8規(guī)范開發(fā), 有的公司不會在乎那些,在我的理解中,程序員如果想走的更高,或者更遠,干任何事情必須得專業(yè)化(本人理解方式), 不要求很多東西都是精通,但最少得有一門精通的語言,小弟在此在大佬面前裝逼了, 忘看過的大牛不要揭穿, 留下你懂的我不懂的知識,大家一起學習,一起進步。 謝謝。

Autopep8是一個將python代碼自動編排的一個工具,它使用pep8工具來決定代碼中的那部分需要被排版,Autopep8可以修復大部分pep8工具中報告的排版問題。很多人都知道 Ctrl+Alt+L 也可以排版, 但是我要告訴你,快捷鍵只是可以簡單的排版。跟Autopep8是無法相比的。

安裝Autopep8:

pip install autopep8

安裝完成之后,import導入一下,測試是否安裝成功。

Aytopep8的使用

安裝完成之后,打開pycharm,創(chuàng)建一個新的python文件, demo.py 將一下代碼放入文件中。

def example1():
  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
    else:
      some_string = """
            Indentation in multiline strings should not be touched.Only actual code should be reindented.
"""

這幾行代碼看上去是不是很亂, 接下來就要使用:Autopep8模塊了

打開cmd找到demo.py的文件的上級目錄,

然后輸入以下命令:

autopep8 --in-place --aggressive --aggressive file.py

file.py 是你的demo.py

輸入命令,按回車執(zhí)行成功是不返回的, 執(zhí)行完成之后就可以了,在次打開文件就可以看到變化了。

import math
import sys


def example1():
  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
    else:
      some_string = """
            Indentation in multiline strings should not be touched.Only actual code should be reindented.
"""

執(zhí)行完Autopep8之后代碼是不是看上去簡潔多了。

有人會說,沒寫一個函數(shù)就執(zhí)行一遍命令, 是不是有點麻煩啊, 是的, 有有點麻煩, 但是pycharm是可以配置的, 配置過程如下:

1: File ---> Settings ---> Tools ---> External Tools

打開之后,可以看見窗體左上角有一個 + 號, 點擊+號添加。

Name: 名稱可以隨意

Program: autopep8    # 前提必須先安裝
Arguments: --in-place --aggressive --aggressive $FilePath$
Working directory: $ProjectFileDir$

Advanced Options
        ---- Outputfilters:
$FILE_PATH$\:$LINE$\:$COLUMN$\:.*

以上配置完成之后點擊 OK 保存即可。

快捷使用:

Tools ---> External Tools ---> Autopep8 鼠標點擊一下即可。

到此這篇關(guān)于Autopep8的使用(python自動編排工具)的文章就介紹到這了,更多相關(guān)Autopep8 使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Pycharm配置autopep8實現(xiàn)流程解析

標簽:信陽 淘寶好評回訪 興安盟 昭通 合肥 濟源 隨州 阜新

巨人網(wǎng)絡通訊聲明:本文標題《Autopep8的使用(python自動編排工具)》,本文關(guān)鍵詞  Autopep8,的,使用,python,自動,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Autopep8的使用(python自動編排工具)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Autopep8的使用(python自動編排工具)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 三门峡市| 莱芜市| 永仁县| 泰兴市| 淅川县| 平顶山市| 延津县| 明溪县| 太原市| 平南县| 蒲江县| 昭苏县| 兰州市| 婺源县| 山阴县| 塔河县| 闻喜县| 理塘县| 盐津县| 合肥市| 赤壁市| 桦南县| 辰溪县| 钟山县| 香格里拉县| 上栗县| 遵化市| 临夏市| 阿瓦提县| 卢龙县| 嘉峪关市| 广平县| 左贡县| 松阳县| 洱源县| 江华| 韶关市| 青州市| 山阳县| 乌兰察布市| 江津市|