码迷,mamicode.com
首页 > 编程语言 > 详细

python coding style / python编程风格

时间:2015-07-02 22:16:39      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

 

#from 《Python 2.7.9 documentation》

  • Use 4-space indentation, and no tabs.

  • #使用4空格缩进,不要使用tab缩进
  • Wrap lines so that they don’t exceed 79 characters.

  • 拆行确保每行不超过79个字符
  • 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).

  • 操作符两侧和逗号后面留空格,但括号里侧不加空格: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).

  • 统一类名和函数名,推荐类名用驼峰命名:SampleClass,函数名用小写和下划线命名:get_page(),尽量用self作为方法的第一个参数
  • Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.

  • 国际化环境中慎用编码,ASCII最佳。(中文环境下,推荐utf-8)

python coding style / python编程风格

标签:

原文地址:http://www.cnblogs.com/GeekRai/p/python_codingstyle.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!