Expand Up @@ -34,11 +34,11 @@ msgstr "我可以在 C 中建立自己的函式嗎?" #: ../../faq/extending.rst:18 msgid "" "Yes, you can create built-in modules containing functions, variables, " "exceptions and even new types in C. This is explained in thedocument :ref: " "`extending-index`." "exceptions and even new types in C. This is explained in the " "document :ref: `extending-index`." msgstr "" "是的,你可以在 C 中建立包含函式、變數、例外甚至新型別的內建模組,:ref: " "`extending-index` 文件中有相關說明。" "是的,你可以在 C 中建立包含函式、變數、例外甚至新型別的內建模 " "組,:ref: `extending-index` 文件中有相關說明。" #: ../../faq/extending.rst:22 msgid "Most intermediate or advanced Python books will also cover this topic." Expand Down Expand Up @@ -73,16 +73,16 @@ msgstr "要編寫你自己的 C 擴充有許多替代方法,取決於你要執 #: ../../faq/extending.rst:44 #, fuzzy msgid "" "`Cython <https://cython.org>`_ and its relative `Pyrex <https://www.csse. " "canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ are compilers that accept a " "slightly modified form of Python and generate the corresponding C code. " "Cython and Pyrex make it possible to write an extension without having to " "learn Python's C API." "`Cython <https://cython.org>`_ and its relative `Pyrex <https://" "www.csse. canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ are compilers that " "accept a slightly modified form of Python and generate the corresponding C " "code. Cython and Pyrex make it possible to write an extension without " "having to learn Python's C API." msgstr "" "`Cython <https://cython.org>`_ 及其相關的 `Pyrex <https://www.csse. " "canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ 是接受稍微修改 Python形式並生成 " "相應的 C 程式碼。 Cython 和 Pyrex 使編寫擴充程式成為可能,而無需學習 Python " "的 C API。" "`Cython <https://cython.org>`_ 及其相關的 `Pyrex <https://" "www.csse. canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ 是接受稍微修改 Python " "形式並生成相應的 C 程式碼。 Cython 和 Pyrex 使編寫擴充程式成為可能,而無需學 " "習 Python 的 C API。" #: ../../faq/extending.rst:50 #, fuzzy Expand Down Expand Up @@ -111,15 +111,15 @@ msgid "" "The highest-level function to do this is :c:func:`PyRun_SimpleString` which " "takes a single string argument to be executed in the context of the module " "``__main__`` and returns ``0`` for success and ``-1`` when an exception " "occurred (including :exc:`SyntaxError`). If you want more control,use :c: " "func:`PyRun_String`; see the source for :c:func:`PyRun_SimpleString` in " "``Python/pythonrun.c``." "occurred (including :exc:`SyntaxError`). If you want more control, " "use :c: func:`PyRun_String`; see the source for :c:func:`PyRun_SimpleString` " "in ``Python/pythonrun.c``." msgstr "" "執行此操作的最高級別函式是 :c:func:`PyRun_SimpleString`,它採用單個字串引數在" "模組 ``__main__`` 的上下文中執行,並回傳 ``0`` 表示成功,``- 1`` 發生例外時" "(包括 :exc:`SyntaxError`)。如果你想要更多的控制,使用 :c:func: " "`PyRun_String`;在 ``Python/pythonrun.c``中查看 :c:func: " "`PyRun_SimpleString` 的原始碼。" "(包括 :exc:`SyntaxError`)。如果你想要更多的控制,使 " "用 :c:func: `PyRun_String`;在 ``Python/pythonrun.c``中查 " "看 :c:func: `PyRun_SimpleString` 的原始碼。" #: ../../faq/extending.rst:72 #, fuzzy Expand All @@ -133,8 +133,8 @@ msgid "" "start symbol :c:data:`Py_eval_input`; it parses an expression, evaluates it " "and returns its value." msgstr "" "呼叫上一個問題中的函式 :c:func:`PyRun_String`開始符號 :c:data: " "`Py_eval_input`;它解析一個運算式,對其求值並回傳它的值。" "呼叫上一個問題中的函式 :c:func:`PyRun_String`開始符 " "號 :c:data: `Py_eval_input`;它解析一個運算式,對其求值並回傳它的值。" #: ../../faq/extending.rst:80 msgid "How do I extract C values from a Python object?" Expand All @@ -145,33 +145,34 @@ msgstr "如何從 Python 物件中提取 C 值?" msgid "" "That depends on the object's type. If it's a tuple, :c:func:`PyTuple_Size` " "returns its length and :c:func:`PyTuple_GetItem` returns the item at a " "specified index. Lists have similar functions, :c:func:`PyList_Size`and :c: " "func:`PyList_GetItem`." "specified index. Lists have similar functions, :c:func:`PyList_Size` " "and :c: func:`PyList_GetItem`." msgstr "" "這取決於物件的型別。如果它是一個元組,:c:func:`PyTuple_Size`回傳它的長度,: " "c:func:`PyTuple_GetItem` 回傳指定索引的項目。列表具有類似的函式:c:func: " "`PyList_Size` 和 :c:func:`PyList_GetItem`。" "這取決於物件的型別。如果它是一個元組,:c:func:`PyTuple_Size`回傳它的長 " "度,: c:func:`PyTuple_GetItem` 回傳指定索引的項目。列表具有類似的函式:" "c:func: `PyList_Size` 和 :c:func:`PyList_GetItem`。" #: ../../faq/extending.rst:87 #, fuzzy msgid "" "For bytes, :c:func:`PyBytes_Size` returns its lengthand :c:func: " "`PyBytes_AsStringAndSize` provides a pointer to its value and its length. " "Note that Python bytes objects may contain null bytes soC's :c:func:`! " "strlen` should not be used." "For bytes, :c:func:`PyBytes_Size` returns its length " "and :c:func: `PyBytes_AsStringAndSize` provides a pointer to its value and " "its length. Note that Python bytes objects may contain null bytes so " "C's :c:func:`! strlen` should not be used." msgstr "" "對於位元組,:c:func:`PyBytes_Size`回傳它的長度,:c:func: " "`PyBytes_AsStringAndSize` 提供指向它的值和長度的指標。請注意,Python 位元組物 " "件可能包含空位元組 ,因此不應使用 C 的 :c:func:`!strlen`。" "對於位元組,:c:func:`PyBytes_Size`回傳它的長 " "度,:c:func: `PyBytes_AsStringAndSize` 提供指向它的值和長度的指標。請注意," "Python 位元組物件可能包含空位元組 ,因此不應使用 C 的 :c:func:`!strlen`。" #: ../../faq/extending.rst:92 msgid "" "To test the type of an object, first make sure it isn't ``NULL``, and then " "use :c:func:`PyBytes_Check`, :c:func:`PyTuple_Check`, :c:func:" "`PyList_Check`, etc." "use :c:func:`PyBytes_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, " "etc." msgstr "" "要測試物件的型別,首先確保它不是 ``NULL``,然後再使用 :c:func:" "`PyBytes_Check`、:c:func:`PyTuple_Check`、:c:func:`PyList_Check` 等函式。" "要測試物件的型別,首先確保它不是 ``NULL``,然後再使" "用 :c:func:`PyBytes_Check`、:c:func:`PyTuple_Check`、:c:func:`PyList_Check` " "等函式。" #: ../../faq/extending.rst:95 #, fuzzy Expand All @@ -184,9 +185,10 @@ msgid "" "al.) and mappings in the PyMapping APIs." msgstr "" "還有一個針對 Python 物件的高級 API,它由所謂的「抽象」介面提供——閱讀 " "``Include/abstract.h`` 了解更多詳細資訊。它允許使用 :c:func:" "`PySequence_Length`、:c:func:`PySequence_GetItem` 等呼叫以及許多其他有用的協" "議(例如數字 (:c:func:`PyNumber_Index) ` 等)和 PyMapping API 中的對映。" "``Include/abstract.h`` 了解更多詳細資訊。它允許使" "用 :c:func:`PySequence_Length`、:c:func:`PySequence_GetItem` 等呼叫以及許多其" "他有用的協議(例如數字 (:c:func:`PyNumber_Index) ` 等)和 PyMapping API 中的" "對映。" #: ../../faq/extending.rst:104 msgid "How do I use Py_BuildValue() to create a tuple of arbitrary length?" Expand Down Expand Up @@ -229,8 +231,8 @@ msgid "" "defined. You are responsible for eventually :c:func:`Py_DECREF`\\ 'ing the " "return value." msgstr "" "這適用於任何具有方法的物件——無論是內建的還是使用者定義的。你負責最終 :c:func: " "`Py_DECREF`\\ 'ing 回傳值。" "這適用於任何具有方法的物件——無論是內建的還是使用者定義的。你負責最 " "終 :c:func: `Py_DECREF`\\ 'ing 回傳值。" #: ../../faq/extending.rst:124 msgid "" Expand Down Expand Up @@ -277,9 +279,9 @@ msgid "" "print_error, or just allow the standard traceback mechanism to work. Then, " "the output will go wherever your ``write()`` method sends it." msgstr "" "在 Python 程式碼中,定義一個支援 ``write()`` 方法的物件。將此物件分配給 : " "data:`sys.stdout` 和 :data:`sys.stderr`。呼叫 print_error,或者只允許標準的回 " "溯機制起作用 。然後,輸出將到達你的 ``write()`` 方法發送它的任何地方。" "在 Python 程式碼中,定義一個支援 ``write()`` 方法的物件。將此物件分配 " "給 : data:`sys.stdout` 和 :data:`sys.stderr`。呼叫 print_error,或者只允許標準 " "的回溯機制起作用 。然後,輸出將到達你的 ``write()`` 方法發送它的任何地方。" #: ../../faq/extending.rst:149 msgid "The easiest way to do this is to use the :class:`io.StringIO` class:" Expand Down Expand Up @@ -356,11 +358,11 @@ msgstr "module = PyImport_ImportModule(\"<modulename>\");" #: ../../faq/extending.rst:188 #, fuzzy msgid "" "If the module hasn't been imported yet (i.e. it is not yet presentin :data: " "`sys.modules`), this initializes the module; otherwise it simply returns the " "value of ``sys.modules[\"<modulename>\"]``. Note that it doesn't enter the " "module into any namespace -- it only ensures it has been initialized and is " "stored in :data:`sys.modules`." "If the module hasn't been imported yet (i.e. it is not yet present " "in :data: `sys.modules`), this initializes the module; otherwise it simply " "returns the value of ``sys.modules[\"<modulename>\"]``. Note that it " "doesn't enter the module into any namespace -- it only ensures it has been " "initialized and is stored in :data:`sys.modules`." msgstr "" "如果模組還沒有被引入(即它還沒有出現在 :data:`sys.modules` 中),這會初始化模" "組;否則它只回傳 ``sys.modules[\"<modulename>\"]`` 的值。請注意,它不會將模組" Expand Down Expand Up @@ -516,9 +518,9 @@ msgid "" "``Parser/myreadline.c`` for more hints." msgstr "" "在 C 中執行此操作的最簡單方法是呼叫:c:func:`PyRun_InteractiveLoop`(可能在單" "獨的執行緒中)並讓 Python 直譯器為你處理輸入。你還可以將 :c:func: " "`PyOS_ReadlineFunctionPointer` 設定為指向你的自定義輸入函式。有關更多提示,請 " "參閱 ``Modules/readline.c`` 和``Parser/myreadline.c``。" "獨的執行緒中)並讓 Python 直譯器為你處理輸入。你還可以 " "將 :c:func: `PyOS_ReadlineFunctionPointer` 設定為指向你的自定義輸入函式。有關 " "更多提示,請參閱 ``Modules/readline.c`` 和``Parser/myreadline.c``。" #: ../../faq/extending.rst:275 msgid "How do I find undefined g++ symbols __builtin_new or __pure_virtual?" Expand All @@ -541,22 +543,22 @@ msgid "" "Can I create an object class with some methods implemented in C and others " "in Python (e.g. through inheritance)?" msgstr "" "我可以用一些用 C 實作的方法和用 Python 實作的其他方法(例如通過繼承 )建立一個" "我可以用一些用 C 實作的方法和用 Python 實作的其他方法(例如透過繼承 )建立一個" "物件類別嗎?" #: ../../faq/extending.rst:285 msgid "" "Yes, you can inherit from built-in classes suchas :class:`int`, :class: " "`list`, :class:`dict`, etc." "Yes, you can inherit from built-in classes such " "as :class:`int`, :class: `list`, :class:`dict`, etc." msgstr "" "是的,你可以繼承內建類別,例如 :class:`int`、:class:`list`、:class:`dict` " "等。" #: ../../faq/extending.rst:288 msgid "" "The Boost Python Library (BPL, https://www.boost.org/libs/python/doc/index. " "html) provides a way of doing this from C++ (i.e. you can inherit from an " "extension class written in C++ using the BPL)." "The Boost Python Library (BPL, https://www.boost.org/libs/python/doc/" "index. html) provides a way of doing this from C++ (i.e. you can inherit from " "an extension class written in C++ using the BPL)." msgstr "" "Boost Python 函式庫(BPL,https://www.boost.org/libs/python/doc/index.html)" "提供了一種從 C++ 執行此操作的方法(即你可以使用 BPL 來繼承用 C++ 編寫的擴充類" Expand Down