Python development _python code style (coding style)

We want to do Python development, I think the code in Python style, we need to look at

It's good for us and their preparation of the code.

Here are 8 important code style matters needing attention:

ONE :  Use 4-space indentation, And no tabs.-- uses 4 key blanks to indent code, do not use the tab key.

4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.

TWO :  Wrap lines so that they don’T exceed 79 characters.-- every line of code should not exceed 79 characters.

This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.

THREE :   Use blank lines to separate functions and classes, And larger blocks of code inside functions. -- in a function or class using a blank line
FOUR :  When possible, Put comments on a line of their own.-- add notes, this can help yourself and others to read code
FIVE :   Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4). in the process of writing code, attention to the use of space, so that your code looks clear, beautiful
SIX :  Name your classes and functions consistently; The Convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument -- the use of hump naming names; use'lower_case_with_underscores' way of naming the method or function
SEVEN :  Don’t use fancy encodings if your code is meant to be used in international environments. Python’s default, UTF-8, Or even plain ASCII work best in any case. - UTF-8 is encoded
EIGHT :  Likewise, don’T use non-ASCII characters in identifiers if there is only the slightest chance people speaking a different language will read or maintain the code.-- do not use non ASCII character identifier

Posted by Molly at November 16, 2013 - 1:46 PM