diff --git a/tutorial/modules.po b/tutorial/modules.po index 11ea8e30bc..04b4e8ab06 100644 --- a/tutorial/modules.po +++ b/tutorial/modules.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-28 20:03+0800\n" -"PO-Revision-Date: 2018-07-30 15:16+0800\n" +"PO-Revision-Date: 2018-08-27 14:03+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Poedit 2.1.1\n" +"X-Generator: Poedit 2.0.9\n" #: ../../tutorial/modules.rst:5 msgid "Modules" @@ -37,9 +37,9 @@ msgid "" msgstr "" "如果從 Python 直譯器離開後又再次進入,之前(幫函式或變數)做的定義都會消失。" "因此,想要寫一些比較長的程式時,你最好使用編輯器來準備要輸入給直譯器的內容," -"並且用該檔案來運行它。這就是一個\\ *腳本(script)*。隨著你的程式越變越長,你" -"可能會想要把它分開成幾個檔案,讓它比較好維護。你可能也會想用一個你之前已經在" -"其他程式寫好的函式,但不想要複製該函式的原始定義到所有使用它的程式裡。" +"並且用該檔案來運行它。這就是一個\\ *腳本(script)*\\ 。隨著你的程式越變越" +"長,你可能會想要把它分開成幾個檔案,讓它比較好維護。你可能也會想用一個你之前" +"已經在其他程式寫好的函式,但不想要複製該函式的原始定義到所有使用它的程式裡。" #: ../../tutorial/modules.rst:16 msgid "" @@ -49,6 +49,10 @@ msgid "" "modules or into the *main* module (the collection of variables that you have " "access to in a script executed at the top level and in calculator mode)." msgstr "" +"為了支援這一點,Python 有一種方法可以將定義放入檔案中,並在腳本或直譯器的互動" +"式實例中使用它們。這種檔案稱為\\ *模組(module)*\\ ;模組中的定義可以\\ *導" +"入(import)*\\ 到其他模組中,或是導入至 \\ *主(main)*\\ 模組(即您在最頂" +"層、計算機模式下執行的腳本中,所使用的變數集合)。" #: ../../tutorial/modules.rst:22 msgid "" @@ -59,12 +63,21 @@ msgid "" "to create a file called :file:`fibo.py` in the current directory with the " "following contents::" msgstr "" +"模組是指包含 Python 定義和語句的檔案,檔案名稱是模組名稱的字尾加上\\ :file:‘." +"py’\\ 。在模組中,模組的名稱(作為字串)可用作全域變數\\ ``__name__``\\ 的" +"值。例如,用您喜歡的文字編輯器在資料夾中創一個名為\\ :file:`fibo.py`\\ 的檔" +"案,內容如下:\n" +"\n" +"::" #: ../../tutorial/modules.rst:45 msgid "" "Now enter the Python interpreter and import this module with the following " "command::" msgstr "" +"現在進入 Python 直譯器並用以下命令導入這個模組:\n" +"\n" +"::" #: ../../tutorial/modules.rst:50 msgid "" @@ -72,15 +85,22 @@ msgid "" "in the current symbol table; it only enters the module name ``fibo`` there. " "Using the module name you can access the functions::" msgstr "" +"這並不會將\\ ``fibo``\\ 中定義的函數名稱直接輸入當前的符號表中;它只會輸入\\ " +"``fibo``\\ 的模組名稱。使用此模組名稱,就可以訪問函數:\n" +"\n" +"::" #: ../../tutorial/modules.rst:61 msgid "" "If you intend to use a function often you can assign it to a local name::" msgstr "" +"如果您打算經常使用其中某個函數,可以將其指定至區域名稱:\n" +"\n" +"::" #: ../../tutorial/modules.rst:71 msgid "More on Modules" -msgstr "" +msgstr "更多有關模組" #: ../../tutorial/modules.rst:73 msgid "" @@ -89,6 +109,9 @@ msgid "" "only the *first* time the module name is encountered in an import statement. " "[#]_ (They are also run if the file is executed as a script.)" msgstr "" +"模組可以包含可執行語句以及函式的定義。這些語句是作為模組的初始化,它們只會在" +"\\ *第一次*\\ 執行模組的導入語句時執行。[#]_(如果檔案被當成腳本執行,也會執" +"行它們)。" #: ../../tutorial/modules.rst:78 msgid "" @@ -99,6 +122,10 @@ msgid "" "know what you are doing you can touch a module's global variables with the " "same notation used to refer to its functions, ``modname.itemname``." msgstr "" +"每個模組都有它自己的私有符號表,模組內定義的函數會把該模組的私有符號表當成全" +"域符號表使用。因此,模組的作者可以在模組中使用全域變數,而不必擔心和使用者的" +"全域變數發生意外的名稱衝突。另一方面,如果你知道自己在做什麼,你可以用這個方" +"式取用模組的全域變數,以相同的符號引用函數,\\ ``modname. itemname``\\ 。" #: ../../tutorial/modules.rst:85 msgid "" @@ -107,6 +134,9 @@ msgid "" "for that matter). The imported module names are placed in the importing " "module's global symbol table." msgstr "" +"在一個模組中可以導入其他模組。把所有的\\ :keyword: `import`\\ 語句放在模組" +"(就這邊來說,腳本也是一樣)的最開頭是個慣例,但並沒有強制。 被導入的模組名稱" +"放置在原模組的全域符號表中。" #: ../../tutorial/modules.rst:90 msgid "" @@ -114,16 +144,25 @@ msgid "" "from a module directly into the importing module's symbol table. For " "example::" msgstr "" +"\\ :keyword: `import`\\ 語句有另一種變形寫法,可以直接將名稱從欲導入的模組," +"直接導入至原模組的符號表中。例如:\n" +"\n" +"::" #: ../../tutorial/modules.rst:97 msgid "" "This does not introduce the module name from which the imports are taken in " "the local symbol table (so in the example, ``fibo`` is not defined)." msgstr "" +"在 import 之後的名稱會被導入,但定義該函數的整個模組名稱並不會被引入在本地符" +"號表中(因此,示例中的\\ ``fibo``\\ 未被定義)。" #: ../../tutorial/modules.rst:100 msgid "There is even a variant to import all names that a module defines::" msgstr "" +"甚至還有另一種變形寫法,可以導入模組定義的所有名稱:\n" +"\n" +"::" #: ../../tutorial/modules.rst:106 msgid "" @@ -132,6 +171,9 @@ msgid "" "an unknown set of names into the interpreter, possibly hiding some things " "you have already defined." msgstr "" +"這個寫法會導入模組中所有的名稱,除了使用底線(\\ ``_``\\ )開頭的名稱。大多數" +"情況下,Python 程式設計師不大使用這種名稱,因為它在直譯器中引入了一組未知的名" +"稱,並且可能隱藏了某些您已經定義的內容。" #: ../../tutorial/modules.rst:111 msgid "" @@ -139,23 +181,33 @@ msgid "" "package is frowned upon, since it often causes poorly readable code. " "However, it is okay to use it to save typing in interactive sessions." msgstr "" +"請注意,一般情況下並不建議從模組或套件中導入\\ ``*``\\ 的做法,因為它通常會導" +"致可讀性較差的程式碼。但若是使用它來保存互動式會話中的鍵入動作,則是可以接受" +"的。" #: ../../tutorial/modules.rst:115 msgid "" "If the module name is followed by :keyword:`as`, then the name following :" "keyword:`as` is bound directly to the imported module." msgstr "" +"如果模組名稱後面出現\\ :keyword: `as`\\ ,則\\ :keyword: `as`\\ 之後的名稱將" +"直接和被導入模組綁定在一起。" #: ../../tutorial/modules.rst:124 msgid "" "This is effectively importing the module in the same way that ``import " "fibo`` will do, with the only difference of it being available as ``fib``." msgstr "" +"這個導入方式和\\ ``import fibo``\\ 同樣有效,唯一的差別是現在要用\\ ``fib``" +"\\ 使用模組。" #: ../../tutorial/modules.rst:127 msgid "" "It can also be used when utilising :keyword:`from` with similar effects::" msgstr "" +"在使用時也可用\\ :keyword:`from`\\ 獲得類似的效果:\n" +"\n" +"::" #: ../../tutorial/modules.rst:136 msgid "" @@ -165,14 +217,21 @@ msgid "" "use :func:`importlib.reload`, e.g. ``import importlib; importlib." "reload(modulename)``." msgstr "" +"出於效率原因,每個模組在每次和直譯器的對話(interpreter session)中僅會導入一" +"次。因此,如果您更改了模組,則必須重啟直譯器 — 或者,如果只是一個要交互測試的" +"模組,可以使用\\ :func:`importlib.reload`。例如:\\ ``import importlib; " +"importlib.reload(modulename)``。" #: ../../tutorial/modules.rst:146 msgid "Executing modules as scripts" -msgstr "" +msgstr "以腳本執行模組" #: ../../tutorial/modules.rst:148 msgid "When you run a Python module with ::" msgstr "" +"當使用以下內容運行 Python 模組時:\n" +"\n" +"::" #: ../../tutorial/modules.rst:152 msgid "" @@ -180,6 +239,10 @@ msgid "" "with the ``__name__`` set to ``\"__main__\"``. That means that by adding " "this code at the end of your module::" msgstr "" +"如同你的導入指令,模組中的代碼會被執行,但 “__name__” 設置為 “” __main__ " +"“”。 這意味著, 通過在模組的末尾添加以下代碼:\n" +"\n" +"::" #: ../../tutorial/modules.rst:160 msgid "" @@ -187,10 +250,15 @@ msgid "" "because the code that parses the command line only runs if the module is " "executed as the \"main\" file:" msgstr "" +"你可以選擇將檔案作為腳本使用或做為欲導入的模組使用,因為解析(parse)命令列的" +"程式碼只會在當模組是 “main “ 檔案時,才會執行:" #: ../../tutorial/modules.rst:169 msgid "If the module is imported, the code is not run::" msgstr "" +"如果導入模組,則不會執行(”main” 區塊內的)程式碼:\n" +"\n" +"::" #: ../../tutorial/modules.rst:174 msgid "" @@ -198,10 +266,12 @@ msgid "" "module, or for testing purposes (running the module as a script executes a " "test suite)." msgstr "" +"這通常是用來為模組提供方便的使用者介面,或者用於測試目的(運作測試套件時,以" +"腳本的方式執行模組)。" #: ../../tutorial/modules.rst:181 msgid "The Module Search Path" -msgstr "" +msgstr "模組的搜尋路徑" #: ../../tutorial/modules.rst:185 msgid "" @@ -210,22 +280,28 @@ msgid "" "file named :file:`spam.py` in a list of directories given by the variable :" "data:`sys.path`. :data:`sys.path` is initialized from these locations:" msgstr "" +"導入一個名為\\ :mod:`spam`\\ 的模組時,直譯器首先會搜尋具有該名稱的內建模組。" +"如果找不到,接下來會在變數\\ :data:`sys.path`:\\ 所給定的資料夾清單之中,搜尋" +"一個名為\\ :file:`spam.py`:\\ 的檔案。\\ :data:`sys.path`:\\ 從這些位置開始進" +"行初始化:" #: ../../tutorial/modules.rst:190 msgid "" "The directory containing the input script (or the current directory when no " "file is specified)." -msgstr "" +msgstr "輸入腳本所位在的資料夾(如未指定檔案時,則是當前資料夾)。" #: ../../tutorial/modules.rst:192 msgid "" ":envvar:`PYTHONPATH` (a list of directory names, with the same syntax as the " "shell variable :envvar:`PATH`)." msgstr "" +"\\ :envvar:`PYTHONPATH`\\ (一連串和 shell 變數\\ :envvar:`PATH`\\ 的語法相同" +"的資料夾名稱)。" #: ../../tutorial/modules.rst:194 msgid "The installation-dependent default." -msgstr "" +msgstr "安裝相關的預設值。" #: ../../tutorial/modules.rst:197 msgid "" @@ -233,6 +309,9 @@ msgid "" "script is calculated after the symlink is followed. In other words the " "directory containing the symlink is **not** added to the module search path." msgstr "" +"在支援符號連結(symlink)的檔案系統中,輸入腳本的所在資料夾是在符號連結之後才" +"被計算的。換言之,包含符號連結的資料夾\\ **並沒有**\\ 增加到模組的搜尋路徑" +"中。" #: ../../tutorial/modules.rst:201 msgid "" @@ -243,10 +322,14 @@ msgid "" "library directory. This is an error unless the replacement is intended. See " "section :ref:`tut-standardmodules` for more information." msgstr "" +"初始化之後,Python 程式可以修改\\ :data:`sys.path`\\ 。執行中腳本的所在資料夾" +"會在搜尋路徑的開頭,在標準函式庫路徑之前。這代表該資料夾中的腳本會優先被載" +"入,而不是函式庫資料夾中相同名稱的模組。除非是有意要做這樣的替換,否則這是一" +"個錯誤。 請參見\\ : ref: `tut-standardmodules`\\ 以瞭解更多資訊。" #: ../../tutorial/modules.rst:212 msgid "\"Compiled\" Python files" -msgstr "" +msgstr "「編譯」Python 檔案" #: ../../tutorial/modules.rst:214 msgid "" @@ -258,6 +341,11 @@ msgid "" "spam.cpython-33.pyc``. This naming convention allows compiled modules from " "different releases and different versions of Python to coexist." msgstr "" +"為了加快載入模組的速度,Python 將每個模組的編譯版本緩存 \\ ``__pycache__``\\ " +"資料夾下,並命名為\\ :file:`module.{version}.pyc`\\ ,此編譯版本是將編譯後的" +"檔案格式進行編碼,且名稱通常會包含 Python 的版本邊號。 例如,在 CPython 3.3 " +"中,spam.py 的編譯版本將被緩存為 \\ ``__pycache__/spam.cpython-33.pyc``\\ 。" +"此命名準則可以讓來自不同版本的編譯模組和 Python 的不同版本同時共存。" #: ../../tutorial/modules.rst:222 msgid "" @@ -267,6 +355,9 @@ msgid "" "independent, so the same library can be shared among systems with different " "architectures." msgstr "" +"Python 根據原始碼最後修改的日期,檢查編譯版本是否過期而需要重新編譯。這是一個" +"完全自動的過程。另外,編譯後的模組獨立於平台,因此不同體系結構的系統之間可以" +"共用同一函式庫。" #: ../../tutorial/modules.rst:227 msgid "" @@ -277,10 +368,13 @@ msgid "" "distribution, the compiled module must be in the source directory, and there " "must not be a source module." msgstr "" +"Python 在兩種情況下不檢查緩存。首先,它總是重新編譯,且不儲存直接從命令列載入" +"的模組的結果。 第二,如果沒有源模組,則不會檢查緩存。要支援非源模組(僅編譯)" +"的發布,編譯後的模組必須位於原始資料夾中,並且不能有源模組。" #: ../../tutorial/modules.rst:234 msgid "Some tips for experts:" -msgstr "" +msgstr "一些給專家的秘訣:" #: ../../tutorial/modules.rst:236 msgid "" @@ -292,6 +386,12 @@ msgid "" "have an ``opt-`` tag and are usually smaller. Future releases may change " "the effects of optimization." msgstr "" +"可以在 Python 命令上使用命令參數(switch)\\ :option:`-O`\\ 或\\ :option:`-" +"OO`\\ 來減小已編譯模組的大小。命令參數\\ ``-O``\\ 刪除 assert 語句,\\ ``OO``" +"\\ 同時刪除 assert 語句和 __doc__ 字串。由於某些程式本身可能已經很依賴於可用" +"這些選項,因此只有在您知道自己在做什麼時,才應使用此選項。 「已優化" +"(Optimized)」模組有\\ ``opt-``\\ 標記,且通常較小。未來的版本可能會改變優化" +"的效果。" #: ../../tutorial/modules.rst:244 msgid "" @@ -299,18 +399,20 @@ msgid "" "when it is read from a ``.py`` file; the only thing that's faster about ``." "pyc`` files is the speed with which they are loaded." msgstr "" +"讀取\\ ``. pyc``\\ 檔案時,程式的執行速度並不會比讀取\\ ``. py``\\ 檔案快。唯" +"一比較快的是地方載入的速度。" #: ../../tutorial/modules.rst:248 msgid "" "The module :mod:`compileall` can create .pyc files for all modules in a " "directory." -msgstr "" +msgstr "模組\\ : mod: `compileall`\\ 可以為資料夾中的所有模組創建 .pyc 檔。" #: ../../tutorial/modules.rst:251 msgid "" "There is more detail on this process, including a flow chart of the " "decisions, in :pep:`3147`." -msgstr "" +msgstr "更多的細節,包括決策流程圖,請參考\\ :pep: `3147`\\ 。" #: ../../tutorial/modules.rst:258 msgid "Standard Modules"