Document directory
- Python coding specifications
Python coding standard indent
Use four spaces as the first indent.
Tab or space
Do not mix tabs and spaces.
Maximum row length
The maximum length of a row is limited to 80 characters.
Blank line
Separates top-level functions and class definitions using two blank rows. The method definition in the class is separated by a blank line. Extra empty rows are used to separate related function groups. Use empty rows to separate logical blocks.
Space in a statement or expression
x = 1y = 2
Note
It is best to write comments in English. The comments that violate the code are not as good as the comments without comments. If the comment is a sentence, the first letter must be capitalized. Add two spaces at the end of a sentence.
- Block comment
Start with # and end #
- Internal comment
Document
All functions and modules should have documents, as shown in the following example:
def kos_root(): """Return the pathname of the KOS root directory.""" global _kos_root if _kos_root: return _kos_root ...def complex(real=0.0, imag=0.0): """Form a complex number. Keyword arguments: real -- the real part (default 0.0) imag -- the imaginary part (default 0.0) """ if imag == 0.0 and real == 0.0: return complex_zero ...
Version Information
To add the version information of the source code, you can write the following code:
__version__ = "$Revision: 6104 ___FCKpd___2quot;# $Source$
This code is added after the module documentation.
Module
The module name must be in lowercase, because the module corresponds to the file name, which is consistent with the file naming rules.
Class
The class name uses the capwords convention. The class used internally is prefixed with an underscore.
Exception name Function
Use lower_case_with_underscores to name the function.
Variable
Variables that do not need to be exported must be underlined.