55#
66# Translators:
77# weihaipy, 2020
8+ # Dai Xu <[email protected] >, 202189#
910#, fuzzy
1011msgid ""
@@ -13,7 +14,7 @@ msgstr ""
1314"Report-Msgid-Bugs-To : \n "
1415"POT-Creation-Date : 2021-01-01 05:02+0000\n "
1516"PO-Revision-Date : 2017-02-16 17:42+0000\n "
16- "Last-Translator : weihaipy, 2020 \n "
17+ "
Last-Translator :
Dai Xu <[email protected] >, 2021 \n"
1718"Language-Team : Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n "
1819"MIME-Version : 1.0\n "
1920"Content-Type : text/plain; charset=UTF-8\n "
@@ -37,6 +38,9 @@ msgid ""
3738"writing some scripts in Python. You can also use it yourself if some of the"
3839" functionality can be written in Python more easily."
3940msgstr ""
41+ "前几章讨论了如何对 Python 进行扩展,也就是如何用 C 函数库 扩展 Python 的功能。反过来也是可以的:将 Python 嵌入到 C/C++"
42+ " 应用程序中丰富其功能。这种嵌入可以让应用程序用 Python 来实现某些功能,而不是用 C 或 C++ 。用途会有很多;比如允许用户用 Python "
43+ "编写一些脚本,以便定制应用程序满足需求。如果某些功能用 Python 编写起来更为容易,那么开发人员自己也能这么干。"
4044
4145#: ../../extending/embedding.rst:20
4246msgid ""
@@ -46,6 +50,8 @@ msgid ""
4650"have nothing to do with Python --- instead, some parts of the application "
4751"occasionally call the Python interpreter to run some Python code."
4852msgstr ""
53+ "Python 的嵌入类似于扩展,但不完全相同。不同之处在于,扩展 Python 时应用程序的主程序仍然是 Python 解释器,而嵌入 Python "
54+ "时的主程序可能与 Python 完全无关——而是应用程序的某些部分偶尔会调用 Python 解释器来运行一些 Python 代码。"
4955
5056#: ../../extending/embedding.rst:26
5157msgid ""
@@ -56,6 +62,8 @@ msgid ""
5662"arguments to Python. Then later you can call the interpreter from any part "
5763"of the application."
5864msgstr ""
65+ "因此,若要嵌入 Python,就要提供自己的主程序。此主程序要做的事情之一就是初始化 Python 解释器。至少得调用函数 "
66+ ":c:func:`Py_Initialize`。还有些可选的调用可向 Python 传递命令行参数。之后即可从应用程序的任何地方调用解释器了。"
5967
6068#: ../../extending/embedding.rst:32
6169msgid ""
@@ -66,20 +74,23 @@ msgid ""
6674"level operations described in the previous chapters to construct and use "
6775"Python objects."
6876msgstr ""
77+ "调用解释器的方式有好几种:可向 :c:func:`PyRun_SimpleString` 传入一个包含 Python 语句的字符串,也可向 "
78+ ":c:func:`PyRun_SimpleFile` 传入一个 stdio "
79+ "文件指针和一个文件名(仅在错误信息中起到识别作用)。还可以调用前面介绍过的底层操作来构造并使用 Python 对象。"
6980
7081#: ../../extending/embedding.rst:42
7182msgid ":ref:`c-api-index`"
72- msgstr ""
83+ msgstr ":ref:`c-api-index` "
7384
7485#: ../../extending/embedding.rst:42
7586msgid ""
7687"The details of Python's C interface are given in this manual. A great deal "
7788"of necessary information can be found here."
78- msgstr ""
89+ msgstr "本文详细介绍了 Python 的 C 接口。这里有大量必要的信息。 "
7990
8091#: ../../extending/embedding.rst:49
8192msgid "Very High Level Embedding"
82- msgstr ""
93+ msgstr "高层次的嵌入 "
8394
8495#: ../../extending/embedding.rst:51
8596msgid ""
@@ -88,6 +99,8 @@ msgid ""
8899"needing to interact with the application directly. This can for example be "
89100"used to perform some operation on a file. ::"
90101msgstr ""
102+ "最简单的 Python 嵌入形式就是采用非常高层的接口。该接口的目标是只执行一段 Python "
103+ "脚本,而无需与应用程序直接交互。比如以下代码可以用来对某个文件进行一些操作。"
91104
92105#: ../../extending/embedding.rst:78
93106msgid ""
@@ -103,10 +116,15 @@ msgid ""
103116":c:func:`PyRun_SimpleFile` function, which saves you the trouble of "
104117"allocating memory space and loading the file contents."
105118msgstr ""
119+ "在 :c:func:`Py_Initialize` 之前,应该先调用 :c:func:`Py_SetProgramName` 函数,以便向解释器告知 "
120+ "Python运行库的路径。接下来,:c:func:`Py_Initialize` 会初始化 Python 解释器,然后执行硬编码的 Python "
121+ "脚本,打印出日期和时间。之后,调用 :c:func:`Py_FinalizeEx` 关闭解释器,程序结束。在真实的程序中,可能需要从其他来源获取 "
122+ "Python 脚本,或许是从文本编辑器例程、文件,或者某个数据库。利用 :c:func:`PyRun_SimpleFile` 函数可以更好地从文件中获取"
123+ " Python 代码,可省去分配内存空间和加载文件内容的麻烦。"
106124
107125#: ../../extending/embedding.rst:93
108126msgid "Beyond Very High Level Embedding: An overview"
109- msgstr ""
127+ msgstr "突破高层次嵌入的限制:概述 "
110128
111129#: ../../extending/embedding.rst:95
112130msgid ""
@@ -116,6 +134,8 @@ msgid ""
116134"calls. At the cost of having to write more C code, you can achieve almost "
117135"anything."
118136msgstr ""
137+ "高级接口能从应用程序中执行任何 Python "
138+ "代码,但至少交换数据可说是相当麻烦的。如若需要交换数据,应使用较低级别的调用。几乎可以实现任何功能,代价是得写更多的 C 代码。"
119139
120140#: ../../extending/embedding.rst:100
121141msgid ""
@@ -124,22 +144,24 @@ msgid ""
124144"previous chapters are still valid. To show this, consider what the extension"
125145" code from Python to C really does:"
126146msgstr ""
147+ "应该注意,尽管意图不同,但扩展 Python 和嵌入 Python 的过程相当类似。前几章中讨论的大多数主题依然有效。为了说明这一点,不妨来看一下从 "
148+ "Python 到 C 的扩展代码到底做了什么:"
127149
128150#: ../../extending/embedding.rst:105
129151msgid "Convert data values from Python to C,"
130152msgstr "转换 Python 的数据值到 C,"
131153
132154#: ../../extending/embedding.rst:107
133155msgid "Perform a function call to a C routine using the converted values, and"
134- msgstr ""
156+ msgstr "用转换后的数据执行 C 程序的函数调用,以及 "
135157
136158#: ../../extending/embedding.rst:109
137159msgid "Convert the data values from the call from C to Python."
138- msgstr ""
160+ msgstr "将调用返回的数据从 C 转换为 Python 格式。 "
139161
140162#: ../../extending/embedding.rst:111
141163msgid "When embedding Python, the interface code does:"
142- msgstr ""
164+ msgstr "嵌入 Python 时,接口代码会这样做: "
143165
144166#: ../../extending/embedding.rst:113
145167msgid "Convert data values from C to Python,"
@@ -149,11 +171,11 @@ msgstr "转换 C 的数据值到 Python,"
149171msgid ""
150172"Perform a function call to a Python interface routine using the converted "
151173"values, and"
152- msgstr ""
174+ msgstr "用转换后的数据执行对 Python 接口的函数调用, "
153175
154176#: ../../extending/embedding.rst:118
155177msgid "Convert the data values from the call from Python to C."
156- msgstr ""
178+ msgstr "将调用返回的数据从 Python 转换为 C 格式。 "
157179
158180#: ../../extending/embedding.rst:120
159181msgid ""
@@ -162,6 +184,8 @@ msgid ""
162184"is the routine that you call between both data conversions. When extending, "
163185"you call a C routine, when embedding, you call a Python routine."
164186msgstr ""
187+ "可见只是数据转换的步骤交换了一下顺序,以顺应跨语言的传输方向。唯一的区别是在两次数据转换之间调用的函数不同。在执行扩展时,调用一个 C "
188+ "函数,而执行嵌入时调用的是个 Python 函数。"
165189
166190#: ../../extending/embedding.rst:125
167191msgid ""
@@ -170,6 +194,8 @@ msgid ""
170194" be understood. Since these aspects do not differ from extending the "
171195"interpreter, you can refer to earlier chapters for the required information."
172196msgstr ""
197+ "本文不会讨论如何将数据从 Python 转换到 C "
198+ "去,反之亦然。另外还假定读者能够正确使用引用并处理错误。由于这些地方与解释器的扩展没有区别,请参考前面的章节以获得所需的信息。"
173199
174200#: ../../extending/embedding.rst:134
175201msgid "Pure Embedding"
@@ -182,6 +208,7 @@ msgid ""
182208"not directly interact with the application (but that will change in the next"
183209" section)."
184210msgstr ""
211+ "第一个程序的目标是执行 Python 脚本中的某个函数。就像高层次接口那样,Python 解释器并不会直接与应用程序进行交互(但下一节将改变这一点)。"
185212
186213#: ../../extending/embedding.rst:141
187214msgid "The code to run a function defined in a Python script is:"
@@ -195,6 +222,9 @@ msgid ""
195222"(let's call the finished executable :program:`call`), and use it to execute "
196223"a Python script, such as:"
197224msgstr ""
225+ "上述代码先利用 ``argv[1]`` 加载 Python 脚本,再调用 ``argv[2]`` 指定的函数。函数的整数参数是 ``argv`` "
226+ "数组中的其余值。如果 :ref:`编译并链接<compiling>` 该程序(此处将最终的可执行程序称作 :program:`call`), "
227+ "并用它执行一个 Python 脚本,例如:"
198228
199229#: ../../extending/embedding.rst:161
200230msgid "then the result should be:"
@@ -206,6 +236,7 @@ msgid ""
206236"is for data conversion between Python and C, and for error reporting. The "
207237"interesting part with respect to embedding Python starts with ::"
208238msgstr ""
239+ "尽管相对其功能而言,该程序体积相当庞大,但大部分代码是用于 Python 和 C 之间的数据转换,以及报告错误。嵌入 Python 的有趣部分从此开始:"
209240
210241#: ../../extending/embedding.rst:178
211242msgid ""
0 commit comments