# Copyright (C) 2001 Python Software Foundation # This file is distributed under the same license as the Python package. # # Translators: # Leon H., 2017 # Weilin Du, 2025 msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-01-02 00:15+0000\n" "PO-Revision-Date: 2025-07-13 14:05+0800\n" "Last-Translator: Weilin Du <1372449351@qq.com>\n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" "Language: zh_TW\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" "X-Generator: Poedit 3.6\n" #: ../../tutorial/appendix.rst:5 msgid "Appendix" msgstr "附錄" #: ../../tutorial/appendix.rst:11 msgid "Interactive Mode" msgstr "互動模式" #: ../../tutorial/appendix.rst:13 msgid "" "There are two variants of the interactive :term:`REPL`. The classic basic " "interpreter is supported on all platforms with minimal line control " "capabilities." msgstr "" "互動式 :term:`REPL` 有兩種變體。經典的基本解釋器在所有平台上都支援,具有最低" "限度的行控制能力(line control capabilities)。" #: ../../tutorial/appendix.rst:17 msgid "" "Since Python 3.13, a new interactive shell is used by default. This one " "supports color, multiline editing, history browsing, and paste mode. To " "disable color, see :ref:`using-on-controlling-color` for details. Function " "keys provide some additional functionality. :kbd:`F1` enters the interactive " "help browser :mod:`pydoc`. :kbd:`F2` allows for browsing command-line " "history with neither output nor the :term:`>>>` and :term:`...` prompts. :" "kbd:`F3` enters \"paste mode\", which makes pasting larger blocks of code " "easier. Press :kbd:`F3` to return to the regular prompt." msgstr "" "自 Python 3.13 起,預設會使用新的互動式 shell。這個 shell 支援顏色、多行編輯、" "歷史瀏覽和貼上模式。要停用顏色,請參閱 :ref:`using-on-controlling-color` 以取" "得詳細資訊。功能鍵提供了一些額外的功能。:kbd:`F1` 進入互動式幫助瀏覽器 :mod:" "`pydoc`。:kbd:`F2` 允許瀏覽命令列歷史,且不會有輸出,也不會有 :term:`>>>` 和 :" "term:`...` 提示。:kbd:`F3` 進入「貼上模式」,這使得貼上較大的程式碼區塊更容" "易。按 :kbd:`F3` 可以返回正常提示。" #: ../../tutorial/appendix.rst:27 msgid "" "When using the new interactive shell, exit the shell by typing :kbd:`exit` " "or :kbd:`quit`. Adding call parentheses after those commands is not required." msgstr "" "使用新的互動 shell 時, 請輸入 :kbd:`exit` 或 :kbd:`quit` 來離開 shell。不需" "要在這些指令後面加上呼叫括號。" #: ../../tutorial/appendix.rst:31 msgid "" "If the new interactive shell is not desired, it can be disabled via the :" "envvar:`PYTHON_BASIC_REPL` environment variable." msgstr "" "如果不需要新的互動式 shell, 可以透過 :envvar:`PYTHON_BASIC_REPL` 環境變數來" "停用它。" #: ../../tutorial/appendix.rst:37 msgid "Error Handling" msgstr "錯誤處理" #: ../../tutorial/appendix.rst:39 msgid "" "When an error occurs, the interpreter prints an error message and a stack " "trace. In interactive mode, it then returns to the primary prompt; when " "input came from a file, it exits with a nonzero exit status after printing " "the stack trace. (Exceptions handled by an :keyword:`except` clause in a :" "keyword:`try` statement are not errors in this context.) Some errors are " "unconditionally fatal and cause an exit with a nonzero exit status; this " "applies to internal inconsistencies and some cases of running out of " "memory. All error messages are written to the standard error stream; normal " "output from executed commands is written to standard output." msgstr "" "當一個錯誤發生時,直譯器會印出一個錯誤訊息和堆疊回溯。在互動模式下,它將返回" "主提示字元;當輸入來自檔案時,它在印出堆疊回溯後以非零退出狀態 (nonzero exit " "status) 退出。(由 :keyword:`except` 子句在 :keyword:`try` 陳述式中處理的例外" "在這種情況下不是錯誤。) 有些錯誤是無條件嚴重的,會導致非零退出狀態;這適用於" "內部不一致和一些記憶體耗盡的情況。所有的錯誤訊息都被寫入標準錯誤輸出;被執行" "指令的正常輸出被寫入標準輸出。" #: ../../tutorial/appendix.rst:49 msgid "" "Typing the interrupt character (usually :kbd:`Control-C` or :kbd:`Delete`) " "to the primary or secondary prompt cancels the input and returns to the " "primary prompt. [#]_ Typing an interrupt while a command is executing raises " "the :exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:" "`try` statement." msgstr "" "向主提示字元或次提示字元輸入中斷字元(通常是 :kbd:`Control-C` 或 :kbd:" "`Delete` )會取消輸入並回傳到主提示字元。[#]_ 在指令執行過程中輸入一個中斷," "會引發 :exc:`KeyboardInterrupt` 例外,但可以透過 :keyword:`try` 陳述式來處" "理。" #: ../../tutorial/appendix.rst:59 msgid "Executable Python Scripts" msgstr "可執行的 Python 腳本" #: ../../tutorial/appendix.rst:61 msgid "" "On BSD'ish Unix systems, Python scripts can be made directly executable, " "like shell scripts, by putting the line ::" msgstr "" "在類 BSD 的 Unix 系統上,Python 腳本可以直接執行,就像 shell 腳本一樣,透過放" "置以下這行: ::" #: ../../tutorial/appendix.rst:64 msgid "#!/usr/bin/env python3" msgstr "#!/usr/bin/env python3" #: ../../tutorial/appendix.rst:66 msgid "" "(assuming that the interpreter is on the user's :envvar:`PATH`) at the " "beginning of the script and giving the file an executable mode. The ``#!`` " "must be the first two characters of the file. On some platforms, this first " "line must end with a Unix-style line ending (``'\\n'``), not a Windows " "(``'\\r\\n'``) line ending. Note that the hash, or pound, character, " "``'#'``, is used to start a comment in Python." msgstr "" "(假設直譯器在用戶的 :envvar:`PATH` 上)在腳本的開頭並給檔案一個可執行模式。" "``#!`` 必須是檔案的前兩個字元。在某些平台上,第一行必須以 Unix 樣式的換行 " "(``'\\n'``) 結尾,而不是 Windows (``'\\r\\n'``) 換行。請注意,井號 ``'#'`` 用" "於在 Python 中開始註解。" #: ../../tutorial/appendix.rst:73 msgid "" "The script can be given an executable mode, or permission, using the :" "program:`chmod` command." msgstr "可以使用 :program:`chmod` 指令為腳本賦予可執行模式或權限。" #: ../../tutorial/appendix.rst:76 msgid "$ chmod +x myscript.py" msgstr "$ chmod +x myscript.py" #: ../../tutorial/appendix.rst:80 msgid "" "On Windows systems, there is no notion of an \"executable mode\". The " "Python installer automatically associates ``.py`` files with ``python.exe`` " "so that a double-click on a Python file will run it as a script. The " "extension can also be ``.pyw``, in that case, the console window that " "normally appears is suppressed." msgstr "" "在 Windows 系統上,沒有「可執行模式」的概念。Python 安裝程式會自動將 ``.py`` " "檔案與 ``python.exe`` 聯繫起來,這樣雙擊 Python 檔案就會作為腳本運行。副檔名" "也可以是 ``.pyw``,在這種情況下,通常會出現的控制台視窗會被隱藏。" #: ../../tutorial/appendix.rst:90 msgid "The Interactive Startup File" msgstr "互動式啟動檔案" #: ../../tutorial/appendix.rst:92 msgid "" "When you use Python interactively, it is frequently handy to have some " "standard commands executed every time the interpreter is started. You can " "do this by setting an environment variable named :envvar:`PYTHONSTARTUP` to " "the name of a file containing your start-up commands. This is similar to " "the :file:`.profile` feature of the Unix shells." msgstr "" "當你互動式地使用 Python 時,每次啟動直譯器時執行一些標準指令是非常方便的。你" "可以透過設置一個名為 :envvar:`PYTHONSTARTUP` 的環境變數來實現,該變數是一個包" "含啟動指令的檔案名。它的功能類似 Unix shell 的 :file:`.profile` 。" #: ../../tutorial/appendix.rst:98 msgid "" "This file is only read in interactive sessions, not when Python reads " "commands from a script, and not when :file:`/dev/tty` is given as the " "explicit source of commands (which otherwise behaves like an interactive " "session). It is executed in the same namespace where interactive commands " "are executed, so that objects that it defines or imports can be used without " "qualification in the interactive session. You can also change the prompts " "``sys.ps1`` and ``sys.ps2`` in this file." msgstr "" "這個檔案只在互動模式中被讀取,當 Python 從腳本中讀取指令時,此檔案不會被讀" "取,當 :file:`/dev/tty` 作為指令的明確來源時也不會(否則表現得像互動模式)。" "它在執行互動式指令的同一命名空間中執行,因此它所定義或 import 的物件可以在互" "動模式中不加限定地使用。你也可以在這個檔案中改變 ``sys.ps1`` 和 ``sys.ps2`` " "等提示字元。" #: ../../tutorial/appendix.rst:106 msgid "" "If you want to read an additional start-up file from the current directory, " "you can program this in the global start-up file using code like ``if os." "path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read())``. If you " "want to use the startup file in a script, you must do this explicitly in the " "script::" msgstr "" "如果你想從目前目錄中讀取一個額外的啟動檔案,你可以在全域啟動檔案中使用類似 " "``if os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read()`` 的程" "式碼設定這個行為。如果你想在一個腳本中使用啟動檔案,你必須在腳本中明確地這樣" "做: ::" #: ../../tutorial/appendix.rst:112 msgid "" "import os\n" "filename = os.environ.get('PYTHONSTARTUP')\n" "if filename and os.path.isfile(filename):\n" " with open(filename) as fobj:\n" " startup_file = fobj.read()\n" " exec(startup_file)" msgstr "" "import os\n" "filename = os.environ.get('PYTHONSTARTUP')\n" "if filename and os.path.isfile(filename):\n" " with open(filename) as fobj:\n" " startup_file = fobj.read()\n" " exec(startup_file)" #: ../../tutorial/appendix.rst:123 msgid "The Customization Modules" msgstr "客製化模組" #: ../../tutorial/appendix.rst:125 msgid "" "Python provides two hooks to let you customize it: :index:`sitecustomize` " "and :index:`usercustomize`. To see how it works, you need first to find the " "location of your user site-packages directory. Start Python and run this " "code::" msgstr "" "Python 提供了兩個鉤子 (hook) 讓你可以將它客製化: :index:`sitecustomize` 和 :" "index:`usercustomize` 。要看它是如何運作的,你首先需要找到你的 site-packages " "的位置。啟動 Python 並運行這段程式碼: ::" #: ../../tutorial/appendix.rst:129 msgid "" ">>> import site\n" ">>> site.getusersitepackages()\n" "'/home/user/.local/lib/python3.x/site-packages'" msgstr "" ">>> import site\n" ">>> site.getusersitepackages()\n" "'/home/user/.local/lib/python3.x/site-packages'" #: ../../tutorial/appendix.rst:133 msgid "" "Now you can create a file named :file:`usercustomize.py` in that directory " "and put anything you want in it. It will affect every invocation of Python, " "unless it is started with the :option:`-s` option to disable the automatic " "import." msgstr "" "現在,你可以在該目錄中建立一個名為 :file:`usercustomize.py` 的檔案,並將你想" "要的任何內容放入其中。它會影響 Python 的每次呼叫,除非它以 :option:`-s` 選項" "啟動以禁用自動 import 。" #: ../../tutorial/appendix.rst:137 msgid "" ":index:`sitecustomize` works in the same way, but is typically created by an " "administrator of the computer in the global site-packages directory, and is " "imported before :index:`usercustomize`. See the documentation of the :mod:" "`site` module for more details." msgstr "" ":index:`sitecustomize` 的運作方式相同,但通常是由電腦的管理員在全域 site-" "packages 目錄下建立,並在 :index:`usercustomize` 之前 import 。更多細節請參" "閱 :mod:`site` 模組的文件。" #: ../../tutorial/appendix.rst:144 msgid "Footnotes" msgstr "註解" #: ../../tutorial/appendix.rst:145 msgid "A problem with the GNU Readline package may prevent this." msgstr "GNU Readline 套件的一個問題可能會阻止這一點。"