@@ -277,6 +277,9 @@ msgid ""
277277"is the routine that you call between both data conversions. When extending, "
278278"you call a C routine, when embedding, you call a Python routine."
279279msgstr ""
280+ "如你所見,資料轉換步驟只是被交換來配合跨語言傳輸的不同方向。唯一的差別是你在"
281+ "兩個資料轉換之間呼叫的例程。當擴充時,你呼叫 C 例程,當嵌入時,你呼叫 Python "
282+ "例程。"
280283
281284#: ../../extending/embedding.rst:144
282285msgid ""
@@ -285,10 +288,13 @@ msgid ""
285288"be understood. Since these aspects do not differ from extending the "
286289"interpreter, you can refer to earlier chapters for the required information."
287290msgstr ""
291+ "本章不會討論如何將資料從 Python 轉換為 C 以及反之。此外,假設已經理解參考的"
292+ "正確使用和錯誤處理。由於這些方面與擴充直譯器沒有不同,你可以參考前面的章節"
293+ "來取得所需資訊。"
288294
289295#: ../../extending/embedding.rst:153
290296msgid "Pure Embedding"
291- msgstr ""
297+ msgstr "純嵌入 "
292298
293299#: ../../extending/embedding.rst:155
294300msgid ""
@@ -297,10 +303,12 @@ msgid ""
297303"directly interact with the application (but that will change in the next "
298304"section)."
299305msgstr ""
306+ "第一個程式的目標是執行 Python 腳本中的函式。就像在非常高階介面的章節中一樣,"
307+ "Python 直譯器不會直接與應用程式互動(但這在下一節會改變)。"
300308
301309#: ../../extending/embedding.rst:160
302310msgid "The code to run a function defined in a Python script is:"
303- msgstr ""
311+ msgstr "執行 Python 腳本中定義函式的程式碼是: "
304312
305313#: ../../extending/embedding.rst:162
306314msgid ""
@@ -386,6 +394,10 @@ msgid ""
386394"(let's call the finished executable :program:`call`), and use it to execute "
387395"a Python script, such as:"
388396msgstr ""
397+ "此程式碼使用 ``argv[1]`` 載入 Python 腳本,並呼叫 ``argv[2]`` 中命名的函式。"
398+ "其整數引數是 ``argv`` 陣列的其他值。如果你 :ref:`編譯並連結 <compiling>` 此"
399+ "程式(我們稱完成的可執行檔為 :program:`call`),並用它來執行 Python 腳本,"
400+ "例如:"
389401
390402#: ../../extending/embedding.rst:171
391403msgid ""
@@ -399,21 +411,26 @@ msgstr ""
399411
400412#: ../../extending/embedding.rst:180
401413msgid "then the result should be:"
402- msgstr ""
414+ msgstr "那麼結果應該是: "
403415
404416#: ../../extending/embedding.rst:182
405417msgid ""
406418"$ call multiply multiply 3 2\n"
407419"Will compute 3 times 2\n"
408420"Result of call: 6"
409421msgstr ""
422+ "$ call multiply multiply 3 2\n"
423+ "Will compute 3 times 2\n"
424+ "Result of call: 6"
410425
411426#: ../../extending/embedding.rst:188
412427msgid ""
413428"Although the program is quite large for its functionality, most of the code "
414429"is for data conversion between Python and C, and for error reporting. The "
415430"interesting part with respect to embedding Python starts with ::"
416431msgstr ""
432+ "雖然對於其功能而言程式相當龐大,但大部分的程式碼是用於 Python 和 C 之間的資料"
433+ "轉換,以及錯誤回報。關於嵌入 Python 的有趣部分開始於 ::"
417434
418435#: ../../extending/embedding.rst:192
419436msgid ""
@@ -430,6 +447,9 @@ msgid ""
430447"which is constructed using the :c:func:`PyUnicode_DecodeFSDefault` data "
431448"conversion routine. ::"
432449msgstr ""
450+ "在初始化直譯器後,腳本使用 :c:func:`PyImport_Import` 載入。此例程需要一個 "
451+ "Python 字串作為其引數,該字串使用 :c:func:`PyUnicode_DecodeFSDefault` 資料"
452+ "轉換例程建構。 ::"
433453
434454#: ../../extending/embedding.rst:202
435455msgid ""
@@ -450,6 +470,9 @@ msgid ""
450470"proceeds by constructing a tuple of arguments as normal. The call to the "
451471"Python function is then made with::"
452472msgstr ""
473+ "一旦腳本載入,我們要找的名稱使用 :c:func:`PyObject_GetAttrString` 檢索。如果"
474+ "名稱存在,且回傳的物件是可呼叫的,你可以安全地假設它是一個函式。程式接著以"
475+ "正常方式建構引數元組。對 Python 函式的呼叫接著以下面方式進行 ::"
453476
454477#: ../../extending/embedding.rst:216
455478msgid "pValue = PyObject_CallObject(pFunc, pArgs);"
@@ -461,10 +484,12 @@ msgid ""
461484"reference to the return value of the function. Be sure to release the "
462485"reference after examining the value."
463486msgstr ""
487+ "函式回傳時,``pValue`` 要不是 ``NULL`` 就是包含函式回傳值的參考。確保在檢查"
488+ "值之後釋放參考。"
464489
465490#: ../../extending/embedding.rst:226
466491msgid "Extending Embedded Python"
467- msgstr ""
492+ msgstr "擴充嵌入式 Python "
468493
469494#: ../../extending/embedding.rst:228
470495msgid ""
@@ -477,6 +502,11 @@ msgid ""
477502"and write some glue code that gives Python access to those routines, just "
478503"like you would write a normal Python extension. For example::"
479504msgstr ""
505+ "到目前為止,嵌入式 Python 直譯器無法存取應用程式本身的功能。Python API 透過"
506+ "擴充嵌入式直譯器來允許這樣做。也就是說,嵌入式直譯器被應用程式提供的例程所"
507+ "擴充。雖然聽起來複雜,但其實沒那麼糟。只要暫時忘記應用程式啟動 Python 直譯器"
508+ "這件事。相反,把應用程式當作一組子程序,並撰寫一些膠合程式碼讓 Python 存取"
509+ "這些例程,就像你撰寫一般 Python 擴充一樣。例如: ::"
480510
481511#: ../../extending/embedding.rst:237
482512msgid ""
@@ -516,6 +546,8 @@ msgid ""
516546"Insert the above code just above the :c:func:`main` function. Also, insert "
517547"the following two statements before the call to :c:func:`Py_Initialize`::"
518548msgstr ""
549+ "在 :c:func:`main` 函式的正上方插入上述程式碼。同時,在呼叫 :c:func:"
550+ "`Py_Initialize` 之前插入以下兩個敘述 ::"
519551
520552#: ../../extending/embedding.rst:270
521553msgid ""
@@ -531,22 +563,26 @@ msgid ""
531563"emb.numargs` function accessible to the embedded Python interpreter. With "
532564"these extensions, the Python script can do things like"
533565msgstr ""
566+ "這兩行初始化 ``numargs`` 變數,並讓 :func:`!emb.numargs` 函式對嵌入式 Python "
567+ "直譯器可用。有了這些擴充,Python 腳本可以執行以下操作"
534568
535569#: ../../extending/embedding.rst:277
536570msgid ""
537571"import emb\n"
538572"print(\" Number of arguments\" , emb.numargs())"
539573msgstr ""
574+ "import emb\n"
575+ "print(\" Number of arguments\" , emb.numargs())"
540576
541577#: ../../extending/embedding.rst:282
542578msgid ""
543579"In a real application, the methods will expose an API of the application to "
544580"Python."
545- msgstr ""
581+ msgstr "在真實的應用程式中,這些方法會向 Python 公開應用程式的 API。 "
546582
547583#: ../../extending/embedding.rst:292
548584msgid "Embedding Python in C++"
549- msgstr ""
585+ msgstr "在 C++ 中嵌入 Python "
550586
551587#: ../../extending/embedding.rst:294
552588msgid ""
@@ -556,10 +592,13 @@ msgid ""
556592"and link your program. There is no need to recompile Python itself using C+"
557593"+."
558594msgstr ""
595+ "也可以將 Python 嵌入 C++ 程式中;具體如何做取決於所使用的 C++ 系統的細節;"
596+ "一般來說,你需要用 C++ 撰寫主程式,並使用 C++ 編譯器來編譯和連結你的程式。"
597+ "不需要使用 C++ 重新編譯 Python 本身。"
559598
560599#: ../../extending/embedding.rst:303
561600msgid "Compiling and Linking under Unix-like systems"
562- msgstr ""
601+ msgstr "在類 Unix 系統下編譯和連結 "
563602
564603#: ../../extending/embedding.rst:305
565604msgid ""
@@ -568,6 +607,9 @@ msgid ""
568607"application, particularly because Python needs to load library modules "
569608"implemented as C dynamic extensions (:file:`.so` files) linked against it."
570609msgstr ""
610+ "要找到傳遞給編譯器(和連結器)的正確旗標以便將 Python 直譯器嵌入你的應用程式"
611+ "中,並不一定是簡單的事,特別是因為 Python 需要載入作為 C 動態擴充實作的函式庫"
612+ "模組(:file:`.so` 檔案)並連結到它。"
571613
572614#: ../../extending/embedding.rst:311
573615msgid ""
@@ -577,12 +619,15 @@ msgid ""
577619"available). This script has several options, of which the following will be "
578620"directly useful to you:"
579621msgstr ""
622+ "要找出所需的編譯器和連結器旗標,你可以執行作為安裝過程的一部分產生的 :file:"
623+ "`python{X.Y}-config` 腳本(也可能有 :file:`python3-config` 腳本可用)。此腳本"
624+ "有幾個選項,其中以下對你直接有用:"
580625
581626#: ../../extending/embedding.rst:317
582627msgid ""
583628"``pythonX.Y-config --cflags`` will give you the recommended flags when "
584629"compiling:"
585- msgstr ""
630+ msgstr "``pythonX.Y-config --cflags`` 會給你編譯時建議的旗標: "
586631
587632#: ../../extending/embedding.rst:320
588633msgid ""
@@ -598,7 +643,7 @@ msgstr ""
598643msgid ""
599644"``pythonX.Y-config --ldflags --embed`` will give you the recommended flags "
600645"when linking:"
601- msgstr ""
646+ msgstr "``pythonX.Y-config --ldflags --embed`` 會給你連結時建議的旗標: "
602647
603648#: ../../extending/embedding.rst:328
604649msgid ""
@@ -617,6 +662,8 @@ msgid ""
617662"that you use the absolute path to :file:`python{X.Y}-config`, as in the "
618663"above example."
619664msgstr ""
665+ "為了避免多個 Python 安裝之間的混淆(特別是系統 Python 和你自己編譯的 Python "
666+ "之間),建議你使用 :file:`python{X.Y}-config` 的絕對路徑,如上面的例子所示。"
620667
621668#: ../../extending/embedding.rst:339
622669msgid ""
@@ -629,6 +676,11 @@ msgid ""
629676"extract the configuration values that you will want to combine together. "
630677"For example:"
631678msgstr ""
679+ "如果此程序對你不起作用(不保證對所有類 Unix 平台都有效;但是,我們歡迎 :ref:"
680+ "`錯誤回報 <reporting-bugs>`),你將必須閱讀系統關於動態連結的文件和/或檢查 "
681+ "Python 的 :file:`Makefile`(使用 :func:`sysconfig.get_makefile_filename` 來"
682+ "找到其位置)和編譯選項。在這種情況下,:mod:`sysconfig` 模組是一個有用的工具,"
683+ "可以程式化地擷取你想要組合在一起的組態值。例如:"
632684
633685#: ../../extending/embedding.rst:348
634686msgid ""
0 commit comments