Article Directory
Encoding format statement
In general, the encoding format declaration is required. If the python source code file does not declare the encoding format, python interpreter will use the default ASCII encoding, once the source file containing non-ASCII character encoding, python interpreter will report an error. In UTF-8, for example, the following two statements are in line with the encoding format rules
# -*- coding: utf-8 -*-
indentation
Unified use 4 spaces to indent. Never use tab, tab and space do not mix. In the case of line connection, I generally use 4 spaces hanging indent. E.g:
var_dict = {
'name': 'xufive',
'mail': '[email protected]'
}
quotation marks
- Natural language use double quotes
- Machine identification to use single quotes
- Regular expressions use double quotes
Blank line
- Encoding format specification, introduced module, two blank lines between the constant and global variable declarations, the definition and execution code top
- Blank blank line between the top two lines between definitions, methods defined
- Inside the function or method, a blank line where necessary to enhance the sense of rhythm, but should avoid consecutive blank lines
Import module
The total import should be placed on top of the file, located behind the module comments and docstrings, before global variables and constants module. Should be introduced in order from most common to least common packet sequence, a blank line between the packet
- Import Standard Library
- Import third-party libraries
- Application specifies import
Naming conventions
- Try to use lowercase module names, initials remain lowercase, try not to use an underscore
- Class names use camel (CamelCase) naming style, capitalized, beginning underscore a private class available
- Function name all lower case, if multiple words separated by underscores
- Private functions are available beginning with an underscore
- Try to lowercase variable names, if multiple words separated by underscores
- Constant all-uppercase, separated if multiple words, use underscores