Skip to content

Commit f430947

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents e17ee8b + 11fda84 commit f430947

11 files changed

+23
-19
lines changed

source/c02/p06_search_replace_case_insensitive.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
'UPPER SNAKE, lower snake, Mixed Snake'
4848
>>>
4949
50-
译者注: ``matchcase('snake')`` 返回了一个回调函数(参数必须是 ``match`` 对象),前面一节一节提到过
50+
译者注: ``matchcase('snake')`` 返回了一个回调函数(参数必须是 ``match`` 对象),前面一节提到过
5151
``sub()`` 函数除了接受替换字符串外,还能接受一个回调函数。
5252

5353
----------

source/c03/p02_accurate_decimal_calculations.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Python新手会倾向于使用 ``decimal`` 模块来处理浮点数的精确运
8080
第二点就是,原生的浮点数计算要快的多-有时候你在执行大量运算的时候速度也是非常重要的。
8181

8282
即便如此,你却不能完全忽略误差。数学家花了大量时间去研究各类算法,有些处理误差会比其他方法更好。
83-
你也得注意下减法删除已经大数和小数的加分运算所带来的影响。比如:
83+
你也得注意下减法删除以及大数和小数的加分运算所带来的影响。比如:
8484

8585
.. code-block:: python
8686

source/c05/p03_print_with_different_separator_or_line_ending.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
----------
4343
讨论
4444
----------
45-
当你想使用非空格分隔符来输出数据的时候,给 ``print()`` 函数传递一个 ``seq`` 参数是最简单的方案。
45+
当你想使用非空格分隔符来输出数据的时候,给 ``print()`` 函数传递一个 ``sep`` 参数是最简单的方案。
4646
有时候你会看到一些程序员会使用 ``str.join()`` 来完成同样的事情。比如:
4747

4848
.. code-block:: python
4949
50-
>>> print(','.join('ACME','50','91.5'))
50+
>>> print(','.join(('ACME','50','91.5')))
5151
ACME,50,91.5
5252
>>>
5353

source/c06/p01_read_write_csv_data.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@
137137

138138
.. code-block::
139139
140-
Street Address,Num-Premises,Latitude,Longitude
141-
5412 N CLARK,10,41.980262,-87.668452
140+
Street Address,Num-Premises,Latitude,Longitude 5412 N CLARK,10,41.980262,-87.668452
142141
143142
这样最终会导致在创建一个命名元组时产生一个 ``ValueError`` 异常而失败。
144143
为了解决这问题,你可能不得不先去修正列标题。

source/c07/p02_functions_that_only_accept_keyword_arguments.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
----------
1111
解决方案
1212
----------
13-
将强制关键字参数放到某个*参数或者当个*后面就能达到这种效果。比如:
13+
将强制关键字参数放到某个*参数或者单个*后面就能达到这种效果。比如:
1414

1515
.. code-block:: python
1616

source/c07/p05_define_functions_with_default_arguments.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@
139139

140140
这里对 ``object()`` 的使用看上去有点不太常见。``object`` 是python中所有类的基类。
141141
你可以创建 ``object`` 类的实例,但是这些实例没什么实际用处,因为它并没有任何有用的方法,
142-
也没有哦任何实例数据(因为它没有任何的实例字典,你甚至都不能设置任何属性值)。
142+
也没有任何实例数据(因为它没有任何的实例字典,你甚至都不能设置任何属性值)。
143143
你唯一能做的就是测试同一性。这个刚好符合我的要求,因为我在函数中就只是需要一个同一性的测试而已。

source/c08/p09_create_new_kind_of_class_or_instance_attribute.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
self.x = x
5050
self.y = y
5151
52-
当你这样做后,所有队描述器属性(比如x或y)的访问会被
52+
当你这样做后,所有对描述器属性(比如x或y)的访问会被
5353
``__get__()`` 、``__set__()`` 和 ``__delete__()`` 方法捕获到。例如:
5454

5555
.. code-block:: python

source/c10/p07_make_directory_or_zip_runnable_as_main_script.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
----------
66
问题
77
----------
8-
您有已经一个复杂的脚本到涉及多个文件的应用程序。你想有一些简单的方法让用户运行程序
8+
您有一个已成长为包含多个文件的应用,它已远不再是一个简单的脚本,你想向用户提供一些简单的方法运行这个程序
99

1010
----------
1111
解决方案

source/c10/p08_read_datafile_within_package.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
首先,一个包对解释器的当前工作目录几乎没有控制权。因此,编程时任何I/O操作都必须使用绝对文件名。由于每个模块包含有完整路径的__file__变量,这弄清楚它的路径不是不可能,但它很凌乱。
3939

4040

41-
第二,包通常安装作为.zip或.egg文件,这些文件像文件系统上的一个普通目录一样不会被保留。因此,你试图用open()对一个包含数据文件的归档文件进行操作,它根本不会工作。
41+
第二,包通常安装作为.zip或.egg文件,这些文件并不像在文件系统上的一个普通目录里那样被保存。因此,你试图用open()对一个包含数据文件的归档文件进行操作,它根本不会工作。
4242

4343

4444
pkgutil.get_data()函数是一个读取数据文件的高级工具,不用管包是如何安装以及安装在哪。它只是工作并将文件内容以字节字符串返回给你

source/c10/p09_add_directories_to_sys_path.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
sys.path.insert(0, '/some/dir')
4949
sys.path.insert(0, '/other/dir')
5050
51-
虽然这能“工作”,它是在实践中极为脆弱,应尽量避免使用。这种方法的问题是,它将目录名硬编码到了你的源。如果你的代码被移到一个新的位置,这会导致维护问题。更好的做法是在不修改源代码的情况下,将path配置到其他地方。如果您使用模块级的变量来精心构造一个适当的绝对路径,有时你可以解决硬编码目录的问题,比如__file__。举个例子:
51+
虽然这能“工作”,它是在实践中极为脆弱,应尽量避免使用。这种方法的问题是,它将目录名硬编码到了你的源代码。如果你的代码被移到一个新的位置,这会导致维护问题。更好的做法是在不修改源代码的情况下,将path配置到其他地方。如果您使用模块级的变量来精心构造一个适当的绝对路径,有时你可以解决硬编码目录的问题,比如__file__。举个例子:
5252
5353
.. code-block:: python
5454
5555
import sys
5656
from os.path import abspath, join, dirname
57-
sys.path.insert(0, abspath(dirname('__file__'), 'src'))
57+
sys.path.insert(0, join(abspath(dirname('__file__')), 'src'))
5858
5959
这将src目录添加到path里,和执行插入步骤的代码在同一个目录里。
6060
61-
site-packages目录是第三方包和模块安装的目录。如果你手动安装你的代码,它将被安装到site-packages目录。虽然.pth文件配置的path必须出现在site-packages里,但代码可以在系统上任何你想要的目录。因此,你可以把你的代码放在一系列不同的目录,只要那些目录包含在.pth文件里。
61+
site-packages目录是第三方包和模块安装的目录。如果你手动安装你的代码,它将被安装到site-packages目录。虽然用于配置path的.pth文件必须放置在site-packages里,但它配置的路径可以是系统上任何你希望的目录。因此,你可以把你的代码放在一系列不同的目录,只要那些目录包含在.pth文件里。
6262

source/c11/p01_interact_with_http_services_as_client.rst

+10-5
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@
114114
content_type = resp.headers['content-type']
115115
content_length = resp.headers['content-length']
116116
117-
Here is a requests example that executes a login into the Python Package index using
118-
basic authentication:
117+
下面是一个利用requests通过基本认证登录Pypi的例子:
118+
119+
.. code-block:: python
120+
119121
import requests
120122
121123
resp = requests.get('http://pypi.python.org/pypi?:action=login',
122124
auth=('user','password'))
123125
124-
Here is an example of using requests to pass HTTP cookies from one request to the
125-
next:
126+
下面是一个利用requests将HTTP cookies从一个请求传递到另一个的例子:
127+
128+
.. code-block:: python
126129
127130
import requests
128131
@@ -133,7 +136,9 @@
133136
# Second requests with cookies received on first requests
134137
resp2 = requests.get(url, cookies=resp1.cookies)
135138
136-
Last, but not least, here is an example of using requests to upload content:
139+
最后但并非最不重要的一个例子是用requests上传内容:
140+
141+
.. code-block:: python
137142
138143
import requests
139144
url = 'http://httpbin.org/post'

0 commit comments

Comments
 (0)