Home Backend Development Python Tutorial Python code standardization tool Flake8

Python code standardization tool Flake8

Oct 18, 2016 am 09:06 AM

Writing code actually needs to be standardized, especially in the team; otherwise Google will not publish various coding standards. The familiar ones include Google C++ Style Guide, Google Python Style Guide, etc.

Are these specifications useful? It's useful but useless, unless you have a good brain and use the standards to your advantage while coding; otherwise we will eventually need a tool to do this. Fortunately, python has more than one tool to help us do this. Stop talking nonsense and get to the point.

Pylint

I have used it and it turned purple. I wonder who is so boring and makes the rules so rigid. Can we pythoners be happy? But if we don’t see rubyer, what does Matz advocate? Is there any Happy Coding? So I’ll leave it alone after using it, because I don’t need to be so perverted, no love~ If you want to install it, it’s very simple:

easy_install pylint // maybe nedd root

Pep8

As the name suggests, it comes from the Python community The famous PEP 8. Basically, just write the code and press this, but this is not perfect enough; the installation is as follows:

easy_install pep8 // maybe nedd root


Pyflakes


Python program passive detection tool, it is really passive , according to the author, it is faster and not powerful enough, but it is okay~

easy_install pyflakes // maybe nedd root

Flake8


The protagonist appears. This is what I recommend, but it does not affect other people's liking of pylint. In fact, this guy is a master, a package of the following three tools:

PyFlakes

Pep8

Ned Batchelder's McCabe script

Not to mention the benefits, the key is scalability, which is clearly stated here: https:/ /pypi.python.org/pypi/flake8/2.0. The installation is as follows:

easy_install flake8 // maybe nedd root

If you like Git like me, then you are also a pythoner, then there are benefits, write the following code into .git/hooks/pre-commit:

#!/usr/bin/env python

import sys

from flake8.hooks import git_hook


COMPLEXITY = 12

STRICT = True


The code is not explained, it is written in the official document It's clear: http://flake8.readthedocs.org/en/latest/vcs.html#git-hook. If your pre-commit script already has rules, that's fine, just call python in the shell.

If you also like vim


as one of the two major artifacts, vim naturally needs a plug-in to enjoy the above tools:

nvie/vim-flake8

vim-scripts/pylint.vim

See By the above list, you should know what I'm talking about. Yes, install it with vundle:

" Flake8 plugin for Vim.

Bundle 'nvie/vim-flake8'

" compiler plugin for python style checking tool .

Bundle 'vim-scripts/pylint.vim'

autocmd FileType python compiler pylint


If you really don’t know vundle, it’s really time to use her: https://github.com/gmarik /vundle. If you find all this troublesome, just use my vimrc, here:


git clone https://github.com/icocoa/icocoa-vimrc.git --recursive vimrc // icocoa is my another account in GitHub


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to get news data bypassing Investing.com's anti-crawler mechanism? How to get news data bypassing Investing.com's anti-crawler mechanism? Apr 02, 2025 am 07:03 AM

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

See all articles