You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
如果包含的任何一个命名空间(package, module or class)是内部的,那么这个接口也被认为是内部接口。
635
635
636
-
Imported names should always be considered an implementation detail. Other modules must not rely on indirect access to such imported names unless they are an explicitly documented part of the containing module's API, such as os.path or a package's \_\_init\_\_module that exposes functionality from submodules.
636
+
导入名应该总是被视为实现细节。其他导入模块一定不能依赖对此导入名的间接访问,除非它们是包含模块 API 的显式文档说明的部分,例如 os.path 或者一个 package 向子模块暴露函数的 \_\_init\_\_模块。
637
637
638
638
<h3id="9">编码建议</h3>
639
639
@@ -652,14 +652,9 @@ Imported names should always be considered an implementation detail. Other modul
* When implementing ordering operations with rich comparisons, it is best to implement all six operations ( \_\_eq\_\_ , \_\_ne\_\_ , \_\_lt\_\_ , \_\_le\_\_ , \_\_gt\_\_ , \_\_ge\_\_ ) rather than relying on other code to only exercise a particular comparison.
657
-
658
-
To minimize the effort involved, the functools.total_ordering() decorator provides a tool to generate missing comparison methods.
659
-
660
-
PEP 207 indicates that reflexivity rules are assumed by Python. Thus, the interpreter may swap y > x with x < y , y >= x with x <= y , and may swap the arguments of x == y and x != y . The sort() and min() operations are guaranteed to use the < operator and the max() function uses the > operator. However, it is best to implement all six operations so that confusion doesn't arise in other contexts.
661
-
662
-
* 使用 def 语句而不用赋值语句直接绑定一个 lambda 表达式到标识符上:
657
+
* 使用 def 语句而不要使用赋值语句去直接绑定一个 lambda 表达式到标识符上:
663
658
664
659
```python
665
660
是:
@@ -671,15 +666,15 @@ PEP 207 indicates that reflexivity rules are assumed by Python. Thus, the interp
671
666
f =lambdax: 2*x
672
667
```
673
668
674
-
The use of the assignment statement eliminates the sole benefit a lambda expression can offer over an explicit def statement (i.e. that it can be embedded inside a larger expression
1、If the exception handler will be printing out or logging the traceback; at least the user will be aware that an error has occurred.
697
693
698
694
2、If the code needs to do some cleanup work, but then lets the exception propagate upwards with raise . try...finally can be a better way to handle this case.
0 commit comments