欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

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

系統 1917 0

目錄

      • 官網
      • 前言
      • 安裝
      • 配置
      • 展示

官網

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

前言

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

autopep8 可以自動格式化 Python 代碼以符合 PEP8 規范。它使用 pycodestyle 實用程序來確定需要格式化代碼的是哪些部分。autopep8 能夠修復 pycodestyle 可以報告的大多數格式問題。只需要使用 autopep8,麻麻再也不用擔心我的代碼不規范了。

安裝

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

pip install autopep8

配置

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

            
              autopep8

            
          

Program:

            
              autopep8

            
          

Arguments:

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

            
          

Working directory:

            
              $ProjectFileDir$

            
          

Output filters:

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

            
          

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

是不是比原來更優美了呢?哈哈哈,到這里就 OK 了。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲黄色一级大片 | 99草在线| 久久久伊人色综合A片无码 国产精品区一区二区三 | 亚洲精品日韩精品一区 | 偶像练习生在线免费观看 | 色秀视频免费网站在线观看 | 色www精品视频在线观看 | 成人在线中文字幕 | 午夜小视频在线 | 天天操天天干天天操 | 色综合久久伊人 | 国产综合久久久久影院 | 国产精品无码永久免费888 | 色六月婷婷 | 91久久亚洲国产成人精品性色 | 欧美性生交大片 | 日韩成人在线观看视频 | 国产精品啪一品二区三区粉嫩 | 欧美黄色一级片视频 | 久久黄视频 | 精品影院 | 波多野结衣一区二区三区88 | 亚洲一本 | 国内自拍视频在线观看 | 亚洲一二三四2021不卡 | 浮力影院最新地址 | 在线精品国内外视频 | 国产精品久久久爽爽爽麻豆色哟哟 | 日色视频 | 美女超碰| 小明台湾www永久视频 | 精品无码国产一区二区日本 | 精品一区二区三区在线观看l | 国产在线精品一区二区三区 | videos高潮 | 亚洲高清成人欧美动作片 | 亚洲精品在线第一页 | 久久久久高清 | 色老头久久网 | 久久夜色精品国产亚洲噜噜 | 奇米狠狠色 |