Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b17d607

Browse files
authored
grammar err
1 parent dbb5094 commit b17d607

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

‎README.md

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
* [Introduction - 简介](#1)
55
* [A Foolish Consistency is the Hobgoblin of Little Minds - 愚蠢的一致性是小心灵的大地精](#2)
66
* [Code lay-out - 代码布局](#3)
7-
* [Indentation - 缩进](#3.1)
8-
* [Tabs or Spaces? - A罩杯还是C罩杯?](#3.2)
9-
* [Maximum Line Length - 代码行最大长度](#3.3)
10-
* [Should a line break before or after a binary operator? - 在二元运算符之前还是之后断行?](#3.4)
11-
* [Blank Lines - 空行](#3.5)
12-
* [Source File Encoding - 源文件编码](#3.6)
13-
* [Imports - 导入](#3.7)
14-
* [Module level dunder names - 模块级 dunder(文中解释) 名称](#3.8)
7+
* [Indentation - 缩进](#3.1)
8+
* [Tabs or Spaces? - A罩杯还是C罩杯?](#3.2)
9+
* [Maximum Line Length - 代码行最大长度](#3.3)
10+
* [Should a line break before or after a binary operator? - 在二元运算符之前还是之后断行?](#3.4)
11+
* [Blank Lines - 空行](#3.5)
12+
* [Source File Encoding - 源文件编码](#3.6)
13+
* [Imports - 导入](#3.7)
14+
* [Module level dunder names - 模块级 dunder(文中解释) 名称](#3.8)
1515
* [String Quotes - 字符串引号](#4)
1616
* [Whitespace in Expressions and Statements - 表达式和语句中的空格](#5)
17-
* [Pet Peeves - 心理藏的小烦恼](#5.1)
18-
* [Other Recommendations - 其他建议](#5.2)
17+
* [Pet Peeves - 心理藏的小烦恼](#5.1)
18+
* [Other Recommendations - 其他建议](#5.2)
1919
* [When to use trailing commas - 何时使用逗号结尾](#6)
2020
* [Comments - 注释](#7)
21-
* [Block Comments - 块注释](#7.1)
22-
* [Inline Comments - 行注释](#7.2)
23-
* [Documentation Strings - 文档字符串](#7.3)
21+
* [Block Comments - 块注释](#7.1)
22+
* [Inline Comments - 行注释](#7.2)
23+
* [Documentation Strings - 文档字符串](#7.3)
2424
* [Naming Conventions - 命名约定](#8)
25-
* [Overriding Principle - 圣经戒律](#8.1)
26-
* [Descriptive: Naming Styles - 描述的: 命名样式](#8.2)
27-
* [Prescriptive: Naming Conventions - 规定的: 命名规定](#8.3)
28-
* [Names to Avoid - 避免的命名](#8.3.1)
29-
* [Package and Module Names - 包和模块名](#8.3.2)
30-
* [Class Names - 类名](#8.3.3)
31-
* [Type variable names - 类型变量名](#8.3.4)
32-
* [Exception Names - 异常名](#8.3.5)
33-
* [Global Variable Names - 全局变量名](#8.3.6)
34-
* [Function Names - 函数名](#8.3.7)
35-
* [Function and method arguments - 函数和方法参数](#8.3.8)
36-
* [Method Names and Instance Variables - 方法名和实例变量](#8.3.9)
37-
* [Constants - 常量](#8.3.10)
38-
* [Designing for inheritance - 继承的设计](#8.3.11)
39-
* [Public and internal interfaces - 公共和内部接口](#8.4)
25+
* [Overriding Principle - 圣经戒律](#8.1)
26+
* [Descriptive: Naming Styles - 描述的: 命名样式](#8.2)
27+
* [Prescriptive: Naming Conventions - 规定的: 命名规定](#8.3)
28+
* [Names to Avoid - 避免的命名](#8.3.1)
29+
* [Package and Module Names - 包和模块名](#8.3.2)
30+
* [Class Names - 类名](#8.3.3)
31+
* [Type variable names - 类型变量名](#8.3.4)
32+
* [Exception Names - 异常名](#8.3.5)
33+
* [Global Variable Names - 全局变量名](#8.3.6)
34+
* [Function Names - 函数名](#8.3.7)
35+
* [Function and method arguments - 函数和方法参数](#8.3.8)
36+
* [Method Names and Instance Variables - 方法名和实例变量](#8.3.9)
37+
* [Constants - 常量](#8.3.10)
38+
* [Designing for inheritance - 继承的设计](#8.3.11)
39+
* [Public and internal interfaces - 公共和内部接口](#8.4)
4040
* [Programming Recommendations - 编码建议](#9)
41-
* [Function Annotations - 函数注释](#9.1)
41+
* [Function Annotations - 函数注释](#9.1)
4242
* [References - 参考文献](#10)
4343
* [Copyright - 版权](#11)
4444

@@ -53,6 +53,7 @@
5353
<h5 id="3.1">缩进</h5>
5454
一个缩进级别四个空格。
5555
* 连续行使用两种方式使封装元素成为一行:括号内垂直隐式连接和悬挂式缩进,使用悬挂式缩进应该注意第一行不应该有参数,连续行要使用进一步的缩进来区分。
56+
5657
```Python
5758
# Aligned with opening delimiter.
5859
foo = long_function_name(var_one, var_two,
@@ -69,7 +70,9 @@ foo = long_function_name(
6970
var_one, var_two,
7071
var_three, var_four)
7172
```
73+
7274
* 当 if 语句过长需要换行时,以下处理方法可以采用。
75+
7376
```Python
7477
# No extra indentation.
7578
if (this_is_one_thing and
@@ -88,7 +91,9 @@ if (this_is_one_thing
8891
and that_is_another_thing):
8992
do_something()
9093
```
94+
9195
* 当闭环括号内元素跨行时,可以采用以下方式。
96+
9297
```Python
9398
my_list = [
9499
1, 2, 3,
@@ -99,6 +104,7 @@ result = some_function_that_takes_arguments(
99104
'd', 'e', 'f',
100105
)
101106
```
107+
102108
<h5 id="3.2">A罩杯还是C罩杯?</h5>
103109
除非项目中已经约定了使用 tab 作为缩进,最好使用 space。
104110
Python 3 不允许 tab 和 space 混用,同时混用了 tab 和 space 的 Python 2 代码应该被转换为仅使用 space。
@@ -107,14 +113,17 @@ Python 3 不允许 tab 和 space 混用,同时混用了 tab 和 space 的 Pyth
107113
对于具有较少结构限制(文档字符串或注释)的长文本块,行长度应限制为72个字符。
108114
当然了,不要问为啥非得是 79,72。我们要兼顾非洲大陆人民的生活。代码是全世界的。
109115
反斜杠有时可能仍然要用。 例如,又多又长的 with - 语句不能使用隐式连接,这时反斜杠是可以接受的:
116+
110117
```Python
111118
with open('/path/to/some/file/you/want/to/read') as file_1, \
112119
open('/path/to/some/file/being/written', 'w') as file_2:
113120
file_2.write(file_1.read())
114121
```
122+
115123
assert 语句也是如此。
116124
<h5 id="3.4">在二元运算符之前还是之后断行?</h5>
117125
算法和程序设计技术先驱,计算机排版系统 TEX 和 METAFONT 的发明者 Donald Knuth,推荐使用以下形式:
126+
118127
```Python
119128
# Yes: easy to match operators with operands
120129
income = (gross_wages
@@ -123,6 +132,7 @@ income = (gross_wages
123132
- ira_deduction
124133
- student_loan_interest)
125134
```
135+
126136
只要保持本地一致性,在二元运算符之前和之后断开都是允许的,但是新的 Python 代码推荐使用 Knuth 形式。
127137
<h5 id="3.5">空行</h5>
128138
顶层函数和类定义使用两个空行。
@@ -135,48 +145,61 @@ Python 2 默认ASCII,Python 3 默认UTF-8。
135145
源文件最好只使用 ASCII 字符,即使是蹩脚的 Chinglish 亦可,家和万事兴。
136146

137147
<h5 id="3.7">模块导入</h5>
148+
138149
```Python
139150
YES: from subprocess import Popen, PIPE
140151
import os
141152
import sys
142153

143154
NO: import sys, os
144155
```
156+
145157
模块导入总是位于文件顶部,在模块注释和文档字符串之后,模块全局变量和常量之前。
146158
导入应该按照以下顺序分组,不同组间用空行隔离。
147159
* 标准库 imports
148160
* 相关第三方 imports
149161
* 本地特定应用/库 imports
150162
推荐使用绝对导入,标准库代码应总是使用绝对导入。
163+
151164
```Python
152165
import mypkg.sibling
153166
from mypkg import sibling
154167
from mypkg.sibling import example
155168
```
169+
156170
在包结构比较复杂时,可以使用相对导入。
171+
157172
```Python
158173
from . import sibling
159174
from .sibling import example
160175
```
176+
161177
在 Python 3 中,相对导入已经被删除,禁止使用。
162178
类导入:
179+
163180
```Python
164181
from myclass import MyClass
165182
from foo.bar.yourclass import YourClass
166183
```
184+
167185
如果这种方式导致了本地命名冲突,可以使用以下方式:
186+
168187
```Python
169188
import myclass
170189
import foo.bar.yourclass
171190
```
191+
172192
然后使用 myclass.MyClass 和 foo.bar.yourclass.YourClass。
173193
请不要使用以下方式:
194+
174195
```Python
175196
from <module> import *
176197
```
198+
177199
<h5 id="3.8">模块级别 dunder 名称</h5>
178200
模块级别 "dunders"(即具有两个前导和两个后缀下划线的名称),例如 \_\_all\_\_,\_\_author\_\_,\_\_version\_\_ 等应放在模块 docstring 之后,但在任何 import 语句之前,但是除了 \_\_future\_\_ 导入。 Python 强制 future-imports 必须在除了 docstrings 之外的任何其他代码之前出现在模块中。
179201
例如:
202+
180203
```Python
181204
"""This is the example module.
182205
@@ -192,6 +215,7 @@ __author__ = 'Cardinal Biggles'
192215
import os
193216
import sys
194217
```
218+
195219
<h5 id="4">字符串引号</h5>
196220
在 Python 中,单引号和双引号是等价的,只需要坚持使用一种并保持一致即可。
197221
在双引号中使用单引号,单引号中使用双引号。三引号中使用双引号。

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /