Skip to content

Commit 891b3ba

Browse files
Merge branch 'master' of github.com:TheRealMilesLee/Python_CookBook
2 parents f807cf2 + 8c0b2ab commit 891b3ba

4 files changed

+6
-4
lines changed

source/c06/p01_read_write_csv_data.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
.. code-block:: python
4343
4444
from collections import namedtuple
45+
import csv
4546
with open('stock.csv') as f:
4647
f_csv = csv.reader(f)
4748
headings = next(f_csv)

source/c11/p11_pass_socket_file_descriptor_between_processes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
问题
77
----------
88
你有多个Python解释器进程在同时运行,你想将某个打开的文件描述符从一个解释器传递给另外一个。
9-
比如,假设有个服务器进程相应连接请求,但是实际的相应逻辑是在另一个解释器中执行的
9+
比如,假设有个服务器进程相应连接请求,但是实际的响应逻辑是在另一个解释器中执行的
1010

1111
----------
1212
解决方案

source/c15/p01_access_ccode_using_ctypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
>>> a = array.array('d',[1,2,3])
256256
>>> a
257257
array('d', [1.0, 2.0, 3.0])
258-
>>> ptr_ = a.buffer_info()
258+
>>> ptr, _ = a.buffer_info()
259259
>>> ptr
260260
4298687200
261261
>>> ctypes.cast(ptr, ctypes.POINTER(ctypes.c_double))

source/c15/p03_write_extension_function_operate_on_arrays.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
::
6161

6262
>>> import array
63+
>>> from sample import *
6364
>>> avg(array.array('d',[1,2,3]))
6465
2.0
6566
>>> import numpy
@@ -95,9 +96,9 @@
9596
通过编写能接受并操作数组的代码,你可以编写很好的兼容这些应用程序的自定义代码,
9697
而不是只能兼容你自己的代码。
9798

98-
代码的关键点在于 ``PyBuffer_GetBuffer()`` 函数。
99+
代码的关键点在于 ``PyObject_GetBuffer()`` 函数。
99100
给定一个任意的Python对象,它会试着去获取底层内存信息,它简单的抛出一个异常并返回-1.
100-
传给 ``PyBuffer_GetBuffer()`` 的特殊标志给出了所需的内存缓冲类型。
101+
传给 ``PyObject_GetBuffer()`` 的特殊标志给出了所需的内存缓冲类型。
101102
例如,``PyBUF_ANY_CONTIGUOUS`` 表示是一个连续的内存区域。
102103

103104
对于数组、字节字符串和其他类似对象而言,一个 ``Py_buffer`` 结构体包含了所有底层内存的信息。

0 commit comments

Comments
 (0)