亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

雜談——Python代碼寫得丑怎么辦?autopep8來幫你

系統(tǒng) 1849 0

目錄

      • 官網(wǎng)
      • 前言
      • 安裝
      • 配置
      • 展示

官網(wǎng)

autopep8 · PyPI——https://pypi.org/project/autopep8/

前言

Python 編程語言需要遵循 PEP8 規(guī)范,但是很多人在編寫代碼時(shí)往往記不住這個(gè)規(guī)范,代碼寫得比較丑。這怎么辦呢?別擔(dān)心,autopep8 來幫你。

autopep8 可以自動(dòng)格式化 Python 代碼以符合 PEP8 規(guī)范。它使用 pycodestyle 實(shí)用程序來確定需要格式化代碼的是哪些部分。autopep8 能夠修復(fù) pycodestyle 可以報(bào)告的大多數(shù)格式問題。只需要使用 autopep8,麻麻再也不用擔(dān)心我的代碼不規(guī)范了。

安裝

使用 pip 進(jìn)行安裝即可,不會安裝 pip 的可以看一下這個(gè)博客——python中pip安裝、升級、升級指定的包。安裝 pip 之后,運(yùn)行 cmd 命令窗。
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第1張圖片
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第2張圖片
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第3張圖片
使用如下命令安裝 autopep8 即可。

pip install autopep8

配置

文件(File)- 設(shè)置(Settings)- 工具(Tools)- 外部工具(External Tools)- 添加(+)
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第4張圖片
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第5張圖片
然后會出現(xiàn)這個(gè)界面,下面就可以設(shè)置配置參數(shù)了。
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第6張圖片
Name:

            
              autopep8

            
          

Program:

            
              autopep8

            
          

Arguments:

            
              --in-place --aggressive --aggressive $FilePath$

            
          

Working directory:

            
              $ProjectFileDir$

            
          

Output filters:

            
              $FILE_PATH$\:$LINE$\:$COLUMN$\:.*

            
          

把上面的配置參數(shù)按照對應(yīng)的名字填寫就可以了,具體配置如下圖:
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第7張圖片
然后點(diǎn)擊 OK - Apply - OK 即可。
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第8張圖片
到這里就已經(jīng)設(shè)置完畢了,使用方法也比較簡單,將鼠標(biāo)在文件編輯器中 - 點(diǎn)擊右鍵 - External Tools - autopep8,這樣就會自動(dòng)運(yùn)行 autopep8,幫你規(guī)范化代碼。
雜談——Python代碼寫得丑怎么辦?autopep8來幫你_第9張圖片

展示

使用 autopep8 前:

            
              
                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
              
                )
              
            
          

使用 autopep8 后:
在這里插入圖片描述

            
              
                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
              
                )
              
            
          

是不是比原來更優(yōu)美了呢?哈哈哈,到這里就 OK 了。


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美一级毛片欧美毛片视频 | 99视频九九精品视频在线观看 | 午夜国产在线 | 国产成人综合精品 | 午夜精品久久久久久久 | 欧美亚洲综合图区在线 | 中文字幕久久网 | 日本亚洲欧美国产日韩ay高清 | 婷婷 综合网站 | 91久久精品一区二区三区 | 一级aa毛片| 国内精品一区二区三区最新 | 色在线视频观看 | 猫咪www免费人成在线观看网址 | 国产精品区一区二区三 | 久久这里只有精品66 | 久久草在线观看 | 日韩视频一区二区在线观看 | 狠狠色狠狠色综合系列 | 日韩影片在线观看 | 亚洲欧美乱综合图片区小说区 | 欧美人拘一级毛片 | 久久精品一区二区三区资源网 | 免费一级毛片视频 | 99久久精品国产一区二区三区 | 国产香蕉98碰碰久久人人 | 日日噜噜夜夜狠狠久久丁香 | 日韩在线手机看片免费看 | 亚洲一区二区三区四区五区 | 日韩成人免费视频 | 国产成人高清亚洲一区91 | 精品日韩二区三区精品视频 | www.夜夜操.com | 在线观看国产一区二三区 | 亚洲黄色高清 | 天天操天天插天天射 | 天天做天天爱天天怼 | 天天射天天干天天色 | 夜间福利在线观看 | 欧美日韩在线成人免费视频大全 | 99j久久精品久久久久久 |