@@ -35,6 +35,12 @@ msgid ""
35
35
"writing some scripts in Python. You can also use it yourself if some of the "
36
36
"functionality can be written in Python more easily."
37
37
msgstr ""
38
+ "前面的章節討論了如何擴充 Python,也就是如何透過附加一個 C 函式庫來擴充 "
39
+ "Python 的功能。但也可以反過來做:將 Python 嵌入你的 C/C++ 應用程式中來豐富"
40
+ "它。嵌入讓你的應用程式能夠以 Python 而非 C 或 C++ 來實作應用程式的某些功能。"
41
+ "這可以用於許多目的;其中一個例子是允許使用者透過撰寫一些 Python 腳本來根據他們"
42
+ "的需求客製化應用程式。如果某些功能用 Python 寫起來比較容易,你也可以自己使用"
43
+ "這種方法。"
38
44
39
45
#: ../../extending/embedding.rst:20
40
46
msgid ""
@@ -44,6 +50,10 @@ msgid ""
44
50
"nothing to do with Python --- instead, some parts of the application "
45
51
"occasionally call the Python interpreter to run some Python code."
46
52
msgstr ""
53
+ "嵌入 Python 與擴充它類似,但不完全相同。差別在於當你擴充 Python 時,應用程式"
54
+ "的主程式仍然是 Python 直譯器,而如果你嵌入 Python,主程式可能與 Python 完全"
55
+ "無關 — 相反,應用程式的某些部分偶爾會呼叫 Python 直譯器來執行一些 Python "
56
+ "程式碼。"
47
57
48
58
#: ../../extending/embedding.rst:26
49
59
msgid ""
@@ -54,6 +64,10 @@ msgid ""
54
64
"Python. Then later you can call the interpreter from any part of the "
55
65
"application."
56
66
msgstr ""
67
+ "所以如果你要嵌入 Python,你要提供自己的主程式。這個主程式必須做的事情之一是"
68
+ "初始化 Python 直譯器。至少,你必須呼叫函式 :c:func:`Py_Initialize`。還有一些"
69
+ "可選的呼叫來傳遞命令列引數給 Python。然後你可以在應用程式的任何部分呼叫直譯"
70
+ "器。"
57
71
58
72
#: ../../extending/embedding.rst:32
59
73
msgid ""
@@ -64,6 +78,10 @@ msgid ""
64
78
"level operations described in the previous chapters to construct and use "
65
79
"Python objects."
66
80
msgstr ""
81
+ "有幾種不同的方式來呼叫直譯器:你可以傳遞一個包含 Python 敘述的字串給 :c:func:"
82
+ "`PyRun_SimpleString`,或者你可以傳遞一個 stdio 檔案指標和檔案名稱(僅用於錯誤"
83
+ "訊息中的識別)給 :c:func:`PyRun_SimpleFile`。你也可以呼叫前面章節中描述的較低"
84
+ "層級操作來建構和使用 Python 物件。"
67
85
68
86
#: ../../extending/embedding.rst:41
69
87
msgid ":ref:`c-api-index`"
@@ -74,10 +92,11 @@ msgid ""
74
92
"The details of Python's C interface are given in this manual. A great deal "
75
93
"of necessary information can be found here."
76
94
msgstr ""
95
+ "Python 的 C 介面詳細資訊在此手冊中提供。大量必要的資訊可以在這裡找到。"
77
96
78
97
#: ../../extending/embedding.rst:49
79
98
msgid "Very High Level Embedding"
80
- msgstr ""
99
+ msgstr "非常高階的嵌入 "
81
100
82
101
#: ../../extending/embedding.rst:51
83
102
msgid ""
@@ -86,6 +105,8 @@ msgid ""
86
105
"needing to interact with the application directly. This can for example be "
87
106
"used to perform some operation on a file. ::"
88
107
msgstr ""
108
+ "嵌入 Python 最簡單的形式是使用非常高階的介面。此介面用於執行 Python 腳本而"
109
+ "無需直接與應用程式互動。這例如可以用來對檔案執行一些操作。 ::"
89
110
90
111
#: ../../extending/embedding.rst:56
91
112
msgid ""
@@ -166,6 +187,9 @@ msgid ""
166
187
"3.13, but we keep it here for backward compatibility. See :ref:`arg-parsing-"
167
188
"string-and-buffers` for a description of this macro."
168
189
msgstr ""
190
+ "``#define PY_SSIZE_T_CLEAN`` 被用來指示某些 API 應該使用 ``Py_ssize_t`` 而不是 "
191
+ "``int``。從 Python 3.13 開始不再必要,但我們在這裡保留它以維持向後相容性。"
192
+ "關於此巨集的描述請參閱 :ref:`arg-parsing-string-and-buffers`。"
169
193
170
194
#: ../../extending/embedding.rst:97
171
195
msgid ""
@@ -181,10 +205,17 @@ msgid ""
181
205
"`PyRun_SimpleFile` function, which saves you the trouble of allocating "
182
206
"memory space and loading the file contents."
183
207
msgstr ""
208
+ "設定 :c:member:`PyConfig.program_name` 應該在 :c:func:`Py_InitializeFromConfig` "
209
+ "之前呼叫,以告知直譯器 Python 執行期函式庫的路徑。接下來,Python 直譯器用 :c:"
210
+ "func:`Py_Initialize` 初始化,然後執行一個硬編碼的 Python 腳本來印出日期和時間。"
211
+ "之後,:c:func:`Py_FinalizeEx` 呼叫會關閉直譯器,接著程式結束。在真實的程式中,"
212
+ "你可能想要從另一個來源取得 Python 腳本,或許是文字編輯器例程、檔案或資料庫。"
213
+ "從檔案取得 Python 程式碼可以更好地使用 :c:func:`PyRun_SimpleFile` 函式來完成,"
214
+ "這樣可以省去分配記憶體空間和載入檔案內容的麻煩。"
184
215
185
216
#: ../../extending/embedding.rst:112
186
217
msgid "Beyond Very High Level Embedding: An overview"
187
- msgstr ""
218
+ msgstr "超越非常高階嵌入:概觀 "
188
219
189
220
#: ../../extending/embedding.rst:114
190
221
msgid ""
@@ -194,6 +225,9 @@ msgid ""
194
225
"calls. At the cost of having to write more C code, you can achieve almost "
195
226
"anything."
196
227
msgstr ""
228
+ "高階介面讓你能夠從應用程式中執行任意的 Python 程式碼片段,但至少可以說交換資料"
229
+ "值是相當麻煩的。如果你想要這樣做,你應該使用較低階的呼叫。以必須撰寫更多 C "
230
+ "程式碼為代價,你幾乎可以達成任何事情。"
197
231
198
232
#: ../../extending/embedding.rst:119
199
233
msgid ""
@@ -202,36 +236,39 @@ msgid ""
202
236
"previous chapters are still valid. To show this, consider what the extension "
203
237
"code from Python to C really does:"
204
238
msgstr ""
239
+ "應該注意的是,儘管意圖不同,擴充 Python 和嵌入 Python 其實是相當相同的活動。"
240
+ "前面章節討論的大部分主題仍然有效。為了說明這一點,考慮從 Python 到 C 的擴充"
241
+ "程式碼真正做了什麼:"
205
242
206
243
#: ../../extending/embedding.rst:124
207
244
msgid "Convert data values from Python to C,"
208
- msgstr ""
245
+ msgstr "將資料值從 Python 轉換為 C, "
209
246
210
247
#: ../../extending/embedding.rst:126
211
248
msgid "Perform a function call to a C routine using the converted values, and"
212
- msgstr ""
249
+ msgstr "使用轉換後的值對 C 例程執行函式呼叫,以及 "
213
250
214
251
#: ../../extending/embedding.rst:128
215
252
msgid "Convert the data values from the call from C to Python."
216
- msgstr ""
253
+ msgstr "將呼叫中的資料值從 C 轉換為 Python。 "
217
254
218
255
#: ../../extending/embedding.rst:130
219
256
msgid "When embedding Python, the interface code does:"
220
- msgstr ""
257
+ msgstr "當嵌入 Python 時,介面程式碼會: "
221
258
222
259
#: ../../extending/embedding.rst:132
223
260
msgid "Convert data values from C to Python,"
224
- msgstr ""
261
+ msgstr "將資料值從 C 轉換為 Python, "
225
262
226
263
#: ../../extending/embedding.rst:134
227
264
msgid ""
228
265
"Perform a function call to a Python interface routine using the converted "
229
266
"values, and"
230
- msgstr ""
267
+ msgstr "使用轉換後的值對 Python 介面例程執行函式呼叫,以及 "
231
268
232
269
#: ../../extending/embedding.rst:137
233
270
msgid "Convert the data values from the call from Python to C."
234
- msgstr ""
271
+ msgstr "將呼叫中的資料值從 Python 轉換為 C。 "
235
272
236
273
#: ../../extending/embedding.rst:139
237
274
msgid ""
0 commit comments