Coding Style for python
2012-02-06 10:23
211 查看
Use 4-space indentation, and no tabs.
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.
Wrap lines so that they don’t exceed 79 characters.
This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
When possible, put comments on a line of their own.
Use docstrings.
Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).
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 (see A First Look at Classes for more on classes and methods).
Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.
looking for more:see http://www.python.org/dev/peps/pep-0008/
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.
Wrap lines so that they don’t exceed 79 characters.
This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
When possible, put comments on a line of their own.
Use docstrings.
Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).
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 (see A First Look at Classes for more on classes and methods).
Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.
looking for more:see http://www.python.org/dev/peps/pep-0008/
相关文章推荐
- JavaScript 编码规范(Google Coding-style for JavaScript)
- PEP8: Style Guide for Python Code
- Style Guide for Python Code
- python之coding style
- python coding style guide 的快速落地实践
- coding style for the linux kernel
- Style Guide for Python Code 推荐的python代码风格
- coding style for the linux kernel
- data style for python
- The RightCoding Style for JAVA
- Web links for coding style
- C++ coding style (for webkit)
- [C/C++] - Tips for Better Coding Style
- Python[三]:Coding Style
- PEP 0008 -- Style Guide for Python Code
- python coding style guide 的高速落地实践
- ARM指令优化-Coding for NEON - Part 4: Shifting Left and Right
- python中的while和for语句的简单使用
- [leetcode]Search for a Range @ Python
- 报错:this class is not key value coding-compliant for the key closeLotTextField解决方法