Python 编码规范 PEP 8
生活随笔
收集整理的這篇文章主要介紹了
Python 编码规范 PEP 8
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
PEP 8 – Style Guide for Python Code
詳情可查看官網
https://www.python.org/dev/peps/pep-0008/
用于查看python代碼是否符合風格.
sudo apt-get install pep8使用
pep8 --youfile.py可以得到以下輸出 test2.py是自己寫的一個文件):
test2.py:1:11: E401 multiple imports one line test2.py:15:13: W92 no newline at end of file顯示的就是出現的一些規范的內容,即使是打多打少幾個空格也會被提示
使用 Pycharm編譯python代碼可直接查看到不符合python編譯風格的代碼
在 Pycharm中選擇 Darcula 格式的顏色顯示,可直接顯示所有的問題。具體可查看 Ubuntu下安裝Pycharm及相關設置
使用python pep8常見問題記錄
import問題
不要在一行中import中引用多個庫
最好這么寫
import os import sys格式問題
E302 expected 2 blank lines,found 0處理:需要再補一個空白行(函數之間需要最少2個空白行,方便查閱、區分)
W292 no newline at end of file處理:在代碼末尾加一行回車即可。
E231 missing whitespace after ‘,’處理:原因簡單來說還是要方便查看,即逗號后“,”需要補空格
print("%s %s %s %s" %(A,B,C,D)) print("%s %s %s %s" % (A, B, C, D))References
https://www.python.org/dev/peps/pep-0008/
http://blog.csdn.net/qq_15437667/article/details/50644904
http://blog.csdn.net/new_light/article/details/40712819
總結
以上是生活随笔為你收集整理的Python 编码规范 PEP 8的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mat中的元素类型(如CV_8U)、范围
- 下一篇: 逍遥情缘辅助职业介绍 辅助职业有什么用