-
Notifications
You must be signed in to change notification settings - Fork 388
Python coding style
Programs must be written for people to read, and only incidentally for machines to execute
-Abelson & Sussman, Structure and Interpretation of Computer Programs
This document talk about the new technique and idioms followed for python contrail code and ways to verify code if based on coding requirement.
PEP 8 (Python Enhancement Proposal) is the de-facto code style guide for Python. A high quality, easy-to-read version of PEP 8 is also available at pep8.org. PEP 8 is a new coding standard adopted by all new juniper python code. You can also refer to following link to learn more about PEP 8: http://www.python.org/dev/peps/pep-0008/ All new code has to adhere to the above standard.
There are many utilities that are avaliable in market for checking PEP8 coding guidelines. Following are few ways to do it.
-
Using pep8
- pip install pep8
- Run your python file with pep8
pep8 optparse.py
-
Using VIM indent
- Download http://www.vim.org/scripts/script.php?script_id=974
- Save to ~/.vim/indent/python.vim
- In vimrc add line
source ~/.vim/indent/python.vim
With Pathogen: Install pathogen in vim: https://github.com/tpope/vim-pathogen
-
Flask 8
- pip install flask8 (Make sure you install flask8 on your m/c)
- Git clone https://github.com/nvie/vim-flake8 repo in ~/.vim/bundle
- Add following lines in your vimrc files let g:flake8_show_in_file=1 let g:flake8_show_in_gutter=1
- Open a Python file Press to run flake8 on it
- For more info checkout : https://github.com/nvie/vim-flake8
-
Python-mode (This is more complicated way but it comes with more feature)
- Git clone https://github.com/klen/python-mode.git ~/.vim/bundle
- Add following lines in your vimrc: " Pathogen load filetype off call pathogen#infect() call pathogen#helptags() filetype plugin indent on syntax on
- When ever you save file your current file will be checked for pep standard
- For more info checkout : https://github.com/python-mode/python-mode
- Using Sublime Package Control
- Use cmd+shift+P shortcut then Package Control: Install Package
- Look for Python PEP8 Autoformat and install it.
References: