@@ -277,6 +277,9 @@ msgid ""
277
277
"is the routine that you call between both data conversions. When extending, "
278
278
"you call a C routine, when embedding, you call a Python routine."
279
279
msgstr ""
280
+ "如你所見,資料轉換步驟只是被交換來配合跨語言傳輸的不同方向。唯一的差別是你在"
281
+ "兩個資料轉換之間呼叫的例程。當擴充時,你呼叫 C 例程,當嵌入時,你呼叫 Python "
282
+ "例程。"
280
283
281
284
#: ../../extending/embedding.rst:144
282
285
msgid ""
@@ -285,10 +288,13 @@ msgid ""
285
288
"be understood. Since these aspects do not differ from extending the "
286
289
"interpreter, you can refer to earlier chapters for the required information."
287
290
msgstr ""
291
+ "本章不會討論如何將資料從 Python 轉換為 C 以及反之。此外,假設已經理解參考的"
292
+ "正確使用和錯誤處理。由於這些方面與擴充直譯器沒有不同,你可以參考前面的章節"
293
+ "來取得所需資訊。"
288
294
289
295
#: ../../extending/embedding.rst:153
290
296
msgid "Pure Embedding"
291
- msgstr ""
297
+ msgstr "純嵌入 "
292
298
293
299
#: ../../extending/embedding.rst:155
294
300
msgid ""
@@ -297,10 +303,12 @@ msgid ""
297
303
"directly interact with the application (but that will change in the next "
298
304
"section)."
299
305
msgstr ""
306
+ "第一個程式的目標是執行 Python 腳本中的函式。就像在非常高階介面的章節中一樣,"
307
+ "Python 直譯器不會直接與應用程式互動(但這在下一節會改變)。"
300
308
301
309
#: ../../extending/embedding.rst:160
302
310
msgid "The code to run a function defined in a Python script is:"
303
- msgstr ""
311
+ msgstr "執行 Python 腳本中定義函式的程式碼是: "
304
312
305
313
#: ../../extending/embedding.rst:162
306
314
msgid ""
@@ -386,6 +394,10 @@ msgid ""
386
394
"(let's call the finished executable :program:`call`), and use it to execute "
387
395
"a Python script, such as:"
388
396
msgstr ""
397
+ "此程式碼使用 ``argv[1]`` 載入 Python 腳本,並呼叫 ``argv[2]`` 中命名的函式。"
398
+ "其整數引數是 ``argv`` 陣列的其他值。如果你 :ref:`編譯並連結 <compiling>` 此"
399
+ "程式(我們稱完成的可執行檔為 :program:`call`),並用它來執行 Python 腳本,"
400
+ "例如:"
389
401
390
402
#: ../../extending/embedding.rst:171
391
403
msgid ""
@@ -399,21 +411,26 @@ msgstr ""
399
411
400
412
#: ../../extending/embedding.rst:180
401
413
msgid "then the result should be:"
402
- msgstr ""
414
+ msgstr "那麼結果應該是: "
403
415
404
416
#: ../../extending/embedding.rst:182
405
417
msgid ""
406
418
"$ call multiply multiply 3 2\n"
407
419
"Will compute 3 times 2\n"
408
420
"Result of call: 6"
409
421
msgstr ""
422
+ "$ call multiply multiply 3 2\n"
423
+ "Will compute 3 times 2\n"
424
+ "Result of call: 6"
410
425
411
426
#: ../../extending/embedding.rst:188
412
427
msgid ""
413
428
"Although the program is quite large for its functionality, most of the code "
414
429
"is for data conversion between Python and C, and for error reporting. The "
415
430
"interesting part with respect to embedding Python starts with ::"
416
431
msgstr ""
432
+ "雖然對於其功能而言程式相當龐大,但大部分的程式碼是用於 Python 和 C 之間的資料"
433
+ "轉換,以及錯誤回報。關於嵌入 Python 的有趣部分開始於 ::"
417
434
418
435
#: ../../extending/embedding.rst:192
419
436
msgid ""
@@ -430,6 +447,9 @@ msgid ""
430
447
"which is constructed using the :c:func:`PyUnicode_DecodeFSDefault` data "
431
448
"conversion routine. ::"
432
449
msgstr ""
450
+ "在初始化直譯器後,腳本使用 :c:func:`PyImport_Import` 載入。此例程需要一個 "
451
+ "Python 字串作為其引數,該字串使用 :c:func:`PyUnicode_DecodeFSDefault` 資料"
452
+ "轉換例程建構。 ::"
433
453
434
454
#: ../../extending/embedding.rst:202
435
455
msgid ""
@@ -450,6 +470,9 @@ msgid ""
450
470
"proceeds by constructing a tuple of arguments as normal. The call to the "
451
471
"Python function is then made with::"
452
472
msgstr ""
473
+ "一旦腳本載入,我們要找的名稱使用 :c:func:`PyObject_GetAttrString` 檢索。如果"
474
+ "名稱存在,且回傳的物件是可呼叫的,你可以安全地假設它是一個函式。程式接著以"
475
+ "正常方式建構引數元組。對 Python 函式的呼叫接著以下面方式進行 ::"
453
476
454
477
#: ../../extending/embedding.rst:216
455
478
msgid "pValue = PyObject_CallObject(pFunc, pArgs);"
@@ -461,10 +484,12 @@ msgid ""
461
484
"reference to the return value of the function. Be sure to release the "
462
485
"reference after examining the value."
463
486
msgstr ""
487
+ "函式回傳時,``pValue`` 要不是 ``NULL`` 就是包含函式回傳值的參考。確保在檢查"
488
+ "值之後釋放參考。"
464
489
465
490
#: ../../extending/embedding.rst:226
466
491
msgid "Extending Embedded Python"
467
- msgstr ""
492
+ msgstr "擴充嵌入式 Python "
468
493
469
494
#: ../../extending/embedding.rst:228
470
495
msgid ""
@@ -477,6 +502,11 @@ msgid ""
477
502
"and write some glue code that gives Python access to those routines, just "
478
503
"like you would write a normal Python extension. For example::"
479
504
msgstr ""
505
+ "到目前為止,嵌入式 Python 直譯器無法存取應用程式本身的功能。Python API 透過"
506
+ "擴充嵌入式直譯器來允許這樣做。也就是說,嵌入式直譯器被應用程式提供的例程所"
507
+ "擴充。雖然聽起來複雜,但其實沒那麼糟。只要暫時忘記應用程式啟動 Python 直譯器"
508
+ "這件事。相反,把應用程式當作一組子程序,並撰寫一些膠合程式碼讓 Python 存取"
509
+ "這些例程,就像你撰寫一般 Python 擴充一樣。例如: ::"
480
510
481
511
#: ../../extending/embedding.rst:237
482
512
msgid ""
@@ -516,6 +546,8 @@ msgid ""
516
546
"Insert the above code just above the :c:func:`main` function. Also, insert "
517
547
"the following two statements before the call to :c:func:`Py_Initialize`::"
518
548
msgstr ""
549
+ "在 :c:func:`main` 函式的正上方插入上述程式碼。同時,在呼叫 :c:func:"
550
+ "`Py_Initialize` 之前插入以下兩個敘述 ::"
519
551
520
552
#: ../../extending/embedding.rst:270
521
553
msgid ""
@@ -531,22 +563,26 @@ msgid ""
531
563
"emb.numargs` function accessible to the embedded Python interpreter. With "
532
564
"these extensions, the Python script can do things like"
533
565
msgstr ""
566
+ "這兩行初始化 ``numargs`` 變數,並讓 :func:`!emb.numargs` 函式對嵌入式 Python "
567
+ "直譯器可用。有了這些擴充,Python 腳本可以執行以下操作"
534
568
535
569
#: ../../extending/embedding.rst:277
536
570
msgid ""
537
571
"import emb\n"
538
572
"print(\" Number of arguments\" , emb.numargs())"
539
573
msgstr ""
574
+ "import emb\n"
575
+ "print(\" Number of arguments\" , emb.numargs())"
540
576
541
577
#: ../../extending/embedding.rst:282
542
578
msgid ""
543
579
"In a real application, the methods will expose an API of the application to "
544
580
"Python."
545
- msgstr ""
581
+ msgstr "在真實的應用程式中,這些方法會向 Python 公開應用程式的 API。 "
546
582
547
583
#: ../../extending/embedding.rst:292
548
584
msgid "Embedding Python in C++"
549
- msgstr ""
585
+ msgstr "在 C++ 中嵌入 Python "
550
586
551
587
#: ../../extending/embedding.rst:294
552
588
msgid ""
@@ -556,10 +592,13 @@ msgid ""
556
592
"and link your program. There is no need to recompile Python itself using C+"
557
593
"+."
558
594
msgstr ""
595
+ "也可以將 Python 嵌入 C++ 程式中;具體如何做取決於所使用的 C++ 系統的細節;"
596
+ "一般來說,你需要用 C++ 撰寫主程式,並使用 C++ 編譯器來編譯和連結你的程式。"
597
+ "不需要使用 C++ 重新編譯 Python 本身。"
559
598
560
599
#: ../../extending/embedding.rst:303
561
600
msgid "Compiling and Linking under Unix-like systems"
562
- msgstr ""
601
+ msgstr "在類 Unix 系統下編譯和連結 "
563
602
564
603
#: ../../extending/embedding.rst:305
565
604
msgid ""
@@ -568,6 +607,9 @@ msgid ""
568
607
"application, particularly because Python needs to load library modules "
569
608
"implemented as C dynamic extensions (:file:`.so` files) linked against it."
570
609
msgstr ""
610
+ "要找到傳遞給編譯器(和連結器)的正確旗標以便將 Python 直譯器嵌入你的應用程式"
611
+ "中,並不一定是簡單的事,特別是因為 Python 需要載入作為 C 動態擴充實作的函式庫"
612
+ "模組(:file:`.so` 檔案)並連結到它。"
571
613
572
614
#: ../../extending/embedding.rst:311
573
615
msgid ""
@@ -577,12 +619,15 @@ msgid ""
577
619
"available). This script has several options, of which the following will be "
578
620
"directly useful to you:"
579
621
msgstr ""
622
+ "要找出所需的編譯器和連結器旗標,你可以執行作為安裝過程的一部分產生的 :file:"
623
+ "`python{X.Y}-config` 腳本(也可能有 :file:`python3-config` 腳本可用)。此腳本"
624
+ "有幾個選項,其中以下對你直接有用:"
580
625
581
626
#: ../../extending/embedding.rst:317
582
627
msgid ""
583
628
"``pythonX.Y-config --cflags`` will give you the recommended flags when "
584
629
"compiling:"
585
- msgstr ""
630
+ msgstr "``pythonX.Y-config --cflags`` 會給你編譯時建議的旗標: "
586
631
587
632
#: ../../extending/embedding.rst:320
588
633
msgid ""
@@ -598,7 +643,7 @@ msgstr ""
598
643
msgid ""
599
644
"``pythonX.Y-config --ldflags --embed`` will give you the recommended flags "
600
645
"when linking:"
601
- msgstr ""
646
+ msgstr "``pythonX.Y-config --ldflags --embed`` 會給你連結時建議的旗標: "
602
647
603
648
#: ../../extending/embedding.rst:328
604
649
msgid ""
@@ -617,6 +662,8 @@ msgid ""
617
662
"that you use the absolute path to :file:`python{X.Y}-config`, as in the "
618
663
"above example."
619
664
msgstr ""
665
+ "為了避免多個 Python 安裝之間的混淆(特別是系統 Python 和你自己編譯的 Python "
666
+ "之間),建議你使用 :file:`python{X.Y}-config` 的絕對路徑,如上面的例子所示。"
620
667
621
668
#: ../../extending/embedding.rst:339
622
669
msgid ""
@@ -629,6 +676,11 @@ msgid ""
629
676
"extract the configuration values that you will want to combine together. "
630
677
"For example:"
631
678
msgstr ""
679
+ "如果此程序對你不起作用(不保證對所有類 Unix 平台都有效;但是,我們歡迎 :ref:"
680
+ "`錯誤回報 <reporting-bugs>`),你將必須閱讀系統關於動態連結的文件和/或檢查 "
681
+ "Python 的 :file:`Makefile`(使用 :func:`sysconfig.get_makefile_filename` 來"
682
+ "找到其位置)和編譯選項。在這種情況下,:mod:`sysconfig` 模組是一個有用的工具,"
683
+ "可以程式化地擷取你想要組合在一起的組態值。例如:"
632
684
633
685
#: ../../extending/embedding.rst:348
634
686
msgid ""
0 commit comments