From 7d170ea5d26da1c04f288337c2f54b7e2708353d Mon Sep 17 00:00:00 2001 From: "Matt.Wang" Date: Sun, 25 Jan 2026 06:28:59 +0800 Subject: [PATCH] translate `whatsnew/2.0.po` --- whatsnew/2.0.po | 642 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 605 insertions(+), 37 deletions(-) diff --git a/whatsnew/2.0.po b/whatsnew/2.0.po index 214719616dd..2eba7d36efe 100644 --- a/whatsnew/2.0.po +++ b/whatsnew/2.0.po @@ -40,6 +40,8 @@ msgid "" "useful changes, and points out a few incompatible changes that may require " "rewriting code." msgstr "" +"Python 的新版本 2.0 於 2000 年 10 月 16 日發布。本文介紹 2.0 中令人興奮的新功" +"能、重點說明一些其他有用的變更,並指出一些可能需要重寫程式碼的不相容變更。" #: ../../whatsnew/2.0.rst:20 msgid "" @@ -52,10 +54,15 @@ msgid "" "for PythonLabs are now getting paid to spend their days fixing bugs, and " "also due to the improved communication resulting from moving to SourceForge." msgstr "" +"Python 的開發在各版本之間從未完全停止,錯誤修正和改進總是源源不斷地被提交。" +"大量的小修正、一些最佳化、額外的說明字串和更好的錯誤訊息都納入了 2.0;要全部" +"列出是不可能的,但它們確實很重要。如果你想看完整的清單,請查閱公開的 CVS 日" +"誌。這些進展歸功於在 PythonLabs 工作的五位開發者現在有薪酬來專職修復錯誤," +"也歸功於遷移到 SourceForge 後改善的溝通。" #: ../../whatsnew/2.0.rst:33 msgid "What About Python 1.6?" -msgstr "" +msgstr "Python 1.6 呢?" #: ../../whatsnew/2.0.rst:35 msgid "" @@ -68,6 +75,11 @@ msgid "" "received a few fixes to ensure that it's forward-compatible with Python " "2.0. 1.6 is therefore part of Python's evolution, and not a side branch." msgstr "" +"Python 1.6 可以被視為履行合約義務的 Python 版本。在核心開發團隊於 2000 年 5 " +"月離開 CNRI 後,CNRI 要求建立一個 1.6 版本,包含所有在 CNRI 完成的 Python 工" +"作。因此 Python 1.6 代表了 2000 年 5 月時 CVS 樹的狀態,最重要的新功能是 " +"Unicode 支援。當然,開發在五月之後仍持續進行,所以 1.6 分支收到了一些修正以" +"確保它與 Python 2.0 向前相容。因此 1.6 是 Python 演進的一部分,而非旁支。" #: ../../whatsnew/2.0.rst:44 msgid "" @@ -80,10 +92,15 @@ msgid "" "2.0. Most of the really interesting features described in this document are " "only in 2.0, because a lot of work was done between May and September." msgstr "" +"那麼,你應該對 Python 1.6 很感興趣嗎?大概不需要。1.6 final 和 2.0 beta1 是" +"在同一天(2000 年 9 月 5 日)釋出的,計畫是在大約一個月內完成 Python 2.0。如" +"果你有應用程式需要維護,遷移到 1.6 導致程式出問題、修復它們、然後一個月內又" +"因遷移到 2.0 而再次出問題,這似乎沒什麼意義;你最好直接升級到 2.0。本文描述" +"的大多數真正有趣的功能只存在於 2.0,因為五月到九月之間完成了大量工作。" #: ../../whatsnew/2.0.rst:57 msgid "New Development Process" -msgstr "" +msgstr "新的開發流程" #: ../../whatsnew/2.0.rst:59 msgid "" @@ -95,6 +112,10 @@ msgid "" "available from Python's project page, located at https://sourceforge.net/" "projects/python/." msgstr "" +"Python 2.0 最重要的變更可能根本不在程式碼,而是 Python 的開發方式:2000 年 5 " +"月,Python 開發者開始使用 SourceForge 提供的工具來儲存原始碼、追蹤錯誤報告和" +"管理補丁提交佇列。要回報錯誤或為 Python 2.0 提交補丁,請使用 Python 專案頁面" +"(位於 https://sourceforge.net/projects/python/)上的錯誤追蹤和補丁管理工具。" #: ../../whatsnew/2.0.rst:66 msgid "" @@ -115,6 +136,16 @@ msgid "" "access, probably that task would have been viewed as \"nice, but not worth " "the time and effort needed\" and it would never have gotten done." msgstr "" +"目前託管在 SourceForge 上最重要的服務是 Python CVS 樹,這是包含 Python 原始碼" +"的版本控制儲存庫。以前大約只有 7 個人左右擁有 CVS 樹的寫入權限,所有補丁都" +"必須由這份短名單上的人檢查並提交。這顯然不太具有擴展性。將 CVS 樹移至 " +"SourceForge 後,可以授予更多人寫入權限;截至 2000 年 9 月,有 27 人能夠提交變" +"更,增加了四倍。這讓我們有機會進行大規模變更,如果這些變更必須經過少數核心開發者" +"過濾,就不會有人嘗試。例如有一天 Peter Schneider-Kamp 突發奇想,決定放棄 " +"K&R C 相容性並將 Python 的 C 原始碼轉換為 ANSI C。在 python-dev 郵件列表上獲" +"得批准後,他開始了持續約一週的密集提交,其他開發者也加入幫忙,工作就完成了。" +"如果只有 5 個人有寫入權限,這項任務可能會被視為「不錯,但不值得花費所需的時間" +"和精力」,永遠不會完成。" #: ../../whatsnew/2.0.rst:83 msgid "" @@ -130,6 +161,12 @@ msgid "" "notification e-mail messages that are completely unhelpful, so Ka-Ping Yee " "wrote an HTML screen-scraper that sends more useful messages." msgstr "" +"轉向使用 SourceForge 的服務使開發速度顯著提升。補丁現在會被提交、評論、由原作" +"者以外的人修改,並在人們之間來回傳遞,直到補丁被認為值得簽入。程式錯誤 (bugs) 在一個集中" +"的位置被追蹤,可以指派給特定的人修復,我們可以計算未解決的錯誤數量來衡量進" +"度。這並非沒有代價:開發者現在有更多電子郵件要處理、更多郵件列表要關注,還必" +"須為新環境編寫特殊工具。例如 SourceForge 發送的預設補丁和錯誤通知電子郵件完" +"全沒有幫助,所以 Ka-Ping Yee 寫了一個 HTML 爬蟲來發送更有用的訊息。" #: ../../whatsnew/2.0.rst:95 msgid "" @@ -145,6 +182,13 @@ msgid "" "can still ignore the result of a vote, and approve or reject a change even " "if the community disagrees with him." msgstr "" +"新增程式碼的便利性造成了一些初期的成長陣痛,例如程式碼在還沒準備好或者還沒有得到開發" +"者群組的明確同意之前就被簽入。已經形成的審批流程與 Apache 組織使用的流程" +"有些類似。開發者可以對補丁投票 +1、+0、-0 或 -1;+1 和 -1 表示接受或拒絕,而 " +"+0 和 -0 表示開發者對該變更基本上持中立態度,但略微傾向正面或負面。與 Apache " +"模式最顯著的不同是,投票本質上只是諮詢性質的,讓擁有「終身仁慈獨裁者」地位的 " +"Guido van Rossum 了解一般意見。即使社群不同意他的意見,他仍然可以忽略投票結" +"果來批准或拒絕一個變更。" #: ../../whatsnew/2.0.rst:106 msgid "" @@ -159,6 +203,12 @@ msgid "" "accepting or rejecting the proposal. Quoting from the introduction " "to :pep:`1`, \"PEP Purpose and Guidelines\":" msgstr "" +"製作實際的補丁是新增功能的最後一步,與早期提出好設計的任務相比通常比較容易。" +"關於新功能的討論往往會爆發成冗長的郵件列表討論串,使討論難以追蹤,而且沒有人" +"能讀完 python-dev 上的每一篇文章。因此,我們以網際網路 RFC 流程為藍本建立" +"了一個相對正式的流程來撰寫 Python 增強提案(PEP)。PEP 是描述提議新功能的" +"草案文件,並持續修改直到社群達成共識以接受或拒絕該提案。引用 :pep:`1`\\ " +"「PEP 目的與準則」的介紹:" #: ../../whatsnew/2.0.rst:120 msgid "" @@ -167,6 +217,9 @@ msgid "" "for Python. The PEP should provide a concise technical specification of the " "feature and a rationale for the feature." msgstr "" +"PEP 代表 Python Enhancement Proposal(Python 增強提案)。PEP 是一份設計文" +"件,向 Python 社群提供資訊,或描述 Python 的新功能。PEP 應該提供該功能的簡潔" +"技術規格和該功能的基本原理。" #: ../../whatsnew/2.0.rst:125 msgid "" @@ -175,6 +228,8 @@ msgid "" "decisions that have gone into Python. The PEP author is responsible for " "building consensus within the community and documenting dissenting opinions." msgstr "" +"我們打算讓 PEP 成為提議新功能、收集社群對議題意見、以及記錄 Python 設計決策的" +"主要機制。PEP 作者負責在社群內建立共識並記錄不同意見。" #: ../../whatsnew/2.0.rst:130 msgid "" @@ -185,6 +240,10 @@ msgid "" "there are 25 PEPs, ranging from :pep:`201`, \"Lockstep Iteration\", to PEP " "225, \"Elementwise/Objectwise Operators\"." msgstr "" +"閱讀 :pep:`1` 的其餘部分以了解 PEP 編輯流程、風格和格式的詳細資訊。PEP 保存在 " +"SourceForge 上的 Python CVS 樹中,雖然它們不是 Python 2.0 發布板的一部分,但" +"也可以從 https://peps.python.org/ 取得 HTML 格式。截至 2000 年 9 月,共有 25 " +"個 PEP,從 :pep:`201` \"Lockstep Iteration\" 到 PEP 225 \"Elementwise/Objectwise Operators\"。" #: ../../whatsnew/2.0.rst:141 msgid "Unicode" @@ -197,6 +256,9 @@ msgid "" "instead of the 8-bit number used by ASCII, meaning that 65,536 distinct " "characters can be supported." msgstr "" +"Python 2.0 中最大的新功能是一個新的基本資料型別:Unicode 字串。Unicode 使用 " +"16 位元數字來表示字元,而不是 ASCII 使用的 8 位元數字,這意味著可以支援 " +"65,536 個不同的字元。" #: ../../whatsnew/2.0.rst:148 msgid "" @@ -207,6 +269,10 @@ msgid "" "was written up as :pep:`100`, \"Python Unicode Integration\". This article " "will simply cover the most significant points about the Unicode interfaces." msgstr "" +"Unicode 支援的最終介面是經過 python-dev 郵件列表上無數次激烈討論後確定的,主" +"要由 Marc-André Lemburg 實作,基於 Fredrik Lundh 的 Unicode 字串型別實作。介" +"面的詳細說明寫在 :pep:`100` \"Python Unicode Integration\" 中。本文僅介紹 " +"Unicode 介面最重要的幾點。" #: ../../whatsnew/2.0.rst:155 msgid "" @@ -217,6 +283,10 @@ msgid "" "be used, and octal escapes can be used for characters up to U+01FF, which is " "represented by ``\\777``." msgstr "" +"在 Python 原始碼中,Unicode 字串寫成 ``u\"string\"``。可以使用新的跳脫序" +"列 :samp:`\\\\u{HHHH}` 來寫入任意 Unicode 字元,其中 *HHHH* 是從 0000 到 FFFF " +"的 4 位十六進位數字。也可以使用現有的 :samp:`\\\\x{HH}` 跳脫序列,而八進位跳" +"脫可用於 U+01FF 以下的字元,以 ``\\777`` 表示。" #: ../../whatsnew/2.0.rst:161 msgid "" @@ -231,30 +301,41 @@ msgid "" "installation by calling the ``sys.setdefaultencoding(encoding)`` function in " "a customized version of :file:`site.py`." msgstr "" +"Unicode 字串就像一般字串是不可變的序列型別。它們可以被索引和切片,但不能原地 (in place) " +"修改。Unicode 字串有一個 ``encode( [encoding] )`` 方法,會回傳所需編碼的 8 " +"位元字串。編碼以字串命名,如 ``'ascii'``、``'utf-8'``、``'iso-8859-1'`` 等。" +"有定義了一個編解碼器 API 來實作和註冊新的編碼,然後就可在整個 Python 程式中使用。" +"如果未指定編碼,預設編碼通常是 7 位元 ASCII,不過可以透過在自訂版本" +"的 :file:`site.py` 中呼叫 ``sys.setdefaultencoding(encoding)`` 函式來為你的 " +"Python 安裝改變它。" #: ../../whatsnew/2.0.rst:172 msgid "" "Combining 8-bit and Unicode strings always coerces to Unicode, using the " "default ASCII encoding; the result of ``'a' + u'bc'`` is ``u'abc'``." msgstr "" +"結合 8 位元字串和 Unicode 字串時,總是會使用預設的 ASCII 編碼強制轉換為 " +"Unicode;``'a' + u'bc'`` 的結果是 ``u'abc'``。" #: ../../whatsnew/2.0.rst:175 msgid "" "New built-in functions have been added, and existing built-ins modified to " "support Unicode:" -msgstr "" +msgstr "新增了內建函式,並修改了現有的內建函式以支援 Unicode:" #: ../../whatsnew/2.0.rst:178 msgid "" "``unichr(ch)`` returns a Unicode string 1 character long, containing the " "character *ch*." -msgstr "" +msgstr "``unichr(ch)`` 會回傳一個長度為 1 的 Unicode 字串,其包含字元 *ch*。" #: ../../whatsnew/2.0.rst:181 msgid "" "``ord(u)``, where *u* is a 1-character regular or Unicode string, returns " "the number of the character as an integer." msgstr "" +"``ord(u)``,其中 *u* 是長度為 1 的一般字串或 Unicode 字串,以整數回傳該字元的" +"數值。" #: ../../whatsnew/2.0.rst:184 msgid "" @@ -266,6 +347,11 @@ msgid "" "errors to be silently ignored and ``'replace'`` uses U+FFFD, the official " "replacement character, in case of any problems." msgstr "" +"``unicode(string [, encoding] [, errors] )`` 從 8 位元字串建立 Unicode 字" +"串。``encoding`` 是指定要使用的編碼的字串。``errors`` 參數指定如何處理目前編" +"碼的無效字元;傳入 ``'strict'`` 作為值會在任何編碼錯誤時引發例外,而 " +"``'ignore'`` 會默默地忽略錯誤,``'replace'`` 則在出現任何問題時使用 U+FFFD(官" +"方替換字元)。" #: ../../whatsnew/2.0.rst:192 msgid "" @@ -275,6 +361,9 @@ msgid "" "built-ins; if you find a built-in function that accepts strings but doesn't " "accept Unicode strings at all, please report it as a bug.)" msgstr "" +"``exec`` 陳述式以及各種內建函式如 ``eval()``、``getattr()`` 和 ``setattr()`` " +"現在也接受 Unicode 字串和一般字串。(在修復過程中可能遺漏了一些內建函式;如果" +"你發現某個接受字串的內建函式完全不接受 Unicode 字串,請當作程式錯誤回報。)" #: ../../whatsnew/2.0.rst:198 msgid "" @@ -284,6 +373,10 @@ msgid "" "it's uppercase. ``unicodedata.bidirectional(u'\\u0660')`` returns 'AN', " "meaning that U+0660 is an Arabic number." msgstr "" +"新模組 :mod:`unicodedata` 提供了 Unicode 字元屬性的介面。例如," +"``unicodedata.category(u'A')`` 回傳 2 字元的字串 'Lu','L' 表示它是字母," +"'u' 表示它是大寫。``unicodedata.bidirectional(u'\\u0660')`` 回傳 'AN',表示 " +"U+0660 是阿拉伯數字。" #: ../../whatsnew/2.0.rst:204 msgid "" @@ -292,6 +385,9 @@ msgid "" "most often use the ``codecs.lookup(encoding)`` function, which returns a 4-" "element tuple: ``(encode_func, decode_func, stream_reader, stream_writer)``." msgstr "" +":mod:`codecs` 模組包含查找現有編碼和註冊新編碼的函式。除非你想實作新的編碼," +"否則最常使用的是 ``codecs.lookup(encoding)`` 函式,它回傳一個 4 元素的元組:" +"``(encode_func, decode_func, stream_reader, stream_writer)``。" #: ../../whatsnew/2.0.rst:209 msgid "" @@ -301,6 +397,9 @@ msgid "" "encoding, and *length* tells you how much of the Unicode string was " "converted." msgstr "" +"*encode_func* 是一個接受 Unicode 字串並回傳 2 元組 ``(string, length)`` 的函" +"式。*string* 是一個 8 位元字串,包含轉換為給定編碼的 Unicode 字串的一部分(可" +"能是全部),*length* 告訴你有多少 Unicode 字串被轉換了。" #: ../../whatsnew/2.0.rst:214 msgid "" @@ -309,6 +408,9 @@ msgid "" "Unicode string *ustring* and the integer *length* telling how much of the 8-" "bit string was consumed." msgstr "" +"*decode_func* 是 *encode_func* 的相反操作,接受一個 8 位元字串並回傳一個 2 元" +"組 ``(ustring, length)``,包含結果 Unicode 字串 *ustring* 和整數 *length*,告" +"訴你消耗了多少 8 位元字串。" #: ../../whatsnew/2.0.rst:219 msgid "" @@ -317,6 +419,9 @@ msgid "" "read`, :meth:`!readline`, and :meth:`!readlines` methods. These methods " "will all translate from the given encoding and return Unicode strings." msgstr "" +"*stream_reader* 是一個支援從串流解碼輸入的類別。*stream_reader(file_obj)* 回" +"傳一個支援 :meth:`!read`、:meth:`!readline` 和 :meth:`!readlines` 方法的物" +"件。這些方法都會從給定的編碼進行轉換並回傳 Unicode 字串。" #: ../../whatsnew/2.0.rst:224 msgid "" @@ -325,12 +430,15 @@ msgid "" "the :meth:`!write` and :meth:`!writelines` methods. These methods expect " "Unicode strings, translating them to the given encoding on output." msgstr "" +"*stream_writer* 同樣是一個支援將輸出編碼到串流的類別。" +"*stream_writer(file_obj)* 回傳一個支援 :meth:`!write` 和 :meth:`!writelines` " +"方法的物件。這些方法預期接收 Unicode 字串,並在輸出時將其轉換為給定的編碼。" #: ../../whatsnew/2.0.rst:229 msgid "" "For example, the following code writes a Unicode string into a file, " "encoding it as UTF-8::" -msgstr "" +msgstr "例如,以下程式碼會將 Unicode 字串寫入檔案並編碼為 UTF-8: ::" #: ../../whatsnew/2.0.rst:232 msgid "" @@ -358,7 +466,7 @@ msgstr "" #: ../../whatsnew/2.0.rst:243 msgid "The following code would then read UTF-8 input from the file::" -msgstr "" +msgstr "以下程式碼接著從檔案讀取 UTF-8 輸入: ::" #: ../../whatsnew/2.0.rst:245 msgid "" @@ -376,6 +484,8 @@ msgid "" "module, which has a new underlying implementation called SRE written by " "Fredrik Lundh of Secret Labs AB." msgstr "" +"支援 Unicode 的正規表示式可透過 :mod:`re` 模組使用,該模組有一個新的底層實" +"作,稱為 SRE,由 Secret Labs AB 的 Fredrik Lundh 編寫。" #: ../../whatsnew/2.0.rst:253 msgid "" @@ -385,6 +495,9 @@ msgid "" "future version of Python may drop support for 8-bit strings and provide only " "Unicode strings." msgstr "" +"新增了 ``-U`` 命令列選項,使 Python 編譯器將所有字串字面值解釋為 Unicode 字串" +"字面值。這是用於測試和讓你的 Python 程式碼面向未來,因為 Python 的某個未來版" +"本可能會放棄對 8 位元字串的支援,只提供 Unicode 字串。" #: ../../whatsnew/2.0.rst:262 msgid "List Comprehensions" @@ -399,6 +512,10 @@ msgid "" "might want to pull out all the strings containing a given substring, or " "strip off trailing whitespace from each line." msgstr "" +"串列是 Python 中的主力資料型別,許多程式在某個時候都會操作串列。對串列的兩個" +"常見操作是對它們進行迴圈,然後選出符合特定條件的元素,或對每個元素套用某個函" +"式。例如,給定一個字串串列,你可能想要取出所有包含特定子字串的字串,或去除每" +"行末尾的空白。" #: ../../whatsnew/2.0.rst:271 msgid "" @@ -411,6 +528,11 @@ msgid "" "paragraph, finding all the strings in the list containing a given " "substring. You could write the following to do it::" msgstr "" +"現有的 :func:`map` 和 :func:`filter` 函式可以用於此目的,但它們需要一個函式作" +"為引數之一。如果有一個現成的內建函式可以直接傳遞就沒問題,但如果沒有的話你必" +"須建立一個小函式來完成所需的工作,而且如果這個小函式需要額外的資訊,Python 的" +"作用域規則會讓結果變得醜陋。以前一段的第一個例子為例,找出串列中所有包含給定" +"子字串的字串。你可以這樣寫來完成它: ::" #: ../../whatsnew/2.0.rst:280 msgid "" @@ -420,6 +542,11 @@ msgid "" " string.find(s, substring) != -1,\n" " L)" msgstr "" +"# 給定串列 L,建立一個包含子字串 S 的\n" +"# 所有字串的串列。\n" +"sublist = filter( lambda s, substring=S:\n" +" string.find(s, substring) != -1,\n" +" L)" #: ../../whatsnew/2.0.rst:286 msgid "" @@ -427,6 +554,8 @@ msgid "" "anonymous function created by the :keyword:`lambda` expression knows what " "substring is being searched for. List comprehensions make this cleaner::" msgstr "" +"由於 Python 的作用域規則,預設引數會被使用,以便 :keyword:`lambda` 運算式建立的" +"匿名函式知道要搜尋的是什麼子字串。串列綜合運算使這更簡潔: ::" #: ../../whatsnew/2.0.rst:290 msgid "sublist = [ s for s in L if string.find(s, S) != -1 ]" @@ -434,7 +563,7 @@ msgstr "sublist = [ s for s in L if string.find(s, S) != -1 ]" #: ../../whatsnew/2.0.rst:292 msgid "List comprehensions have the form::" -msgstr "" +msgstr "串列綜合運算的形式如下: ::" #: ../../whatsnew/2.0.rst:294 msgid "" @@ -458,12 +587,17 @@ msgid "" "final :keyword:`!if` clause is optional; if present, *expression* is only " "evaluated and added to the result if *condition* is true." msgstr "" +":keyword:`!for`...\\ :keyword:`!in` 子句包含要疊代的序列。這些序列不必具有相同" +"的長度,因為它們\\ *不是*\\ 並行疊代的,而是從左到右;這在以下段落中會更清楚" +"地解釋。產生的串列的元素將是 *expression* 的連續值。最後的 :keyword:`!if` 子" +"句是可選的;如果存在,只有當 *condition* 為真時,*expression* 才會被計算並加" +"入結果。" #: ../../whatsnew/2.0.rst:307 msgid "" "To make the semantics very clear, a list comprehension is equivalent to the " "following Python code::" -msgstr "" +msgstr "為了讓語義非常清楚,串列綜合運算等價於以下 Python 程式碼: ::" #: ../../whatsnew/2.0.rst:310 msgid "" @@ -476,6 +610,13 @@ msgid "" " # the expression to the\n" " # resulting list." msgstr "" +"for expr1 in sequence1:\n" +" for expr2 in sequence2:\n" +" ...\n" +" for exprN in sequenceN:\n" +" if (condition):\n" +" # 將運算式的值\n" +" # 附加到結果串列。" #: ../../whatsnew/2.0.rst:319 msgid "" @@ -484,6 +625,8 @@ msgid "" "all the sequences. If you have two lists of length 3, the output list is 9 " "elements long::" msgstr "" +"這意味著當有多個 :keyword:`!for`...\\ :keyword:`!in` 子句時,結果串列的長度將" +"等於所有序列長度的乘積。如果你有兩個長度為 3 的串列,輸出串列將有 9 個元素: ::" #: ../../whatsnew/2.0.rst:324 msgid "" @@ -505,6 +648,8 @@ msgid "" "creating a tuple, it must be surrounded with parentheses. The first list " "comprehension below is a syntax error, while the second one is correct::" msgstr "" +"為了避免在 Python 的文法中引入歧義,如果 *expression* 是建立一個元組,它必須" +"用括號包圍。下面第一個串列綜合運算是語法錯誤,而第二個是正確的: ::" #: ../../whatsnew/2.0.rst:334 msgid "" @@ -526,10 +671,13 @@ msgid "" "comprehension patch, which was then discussed for a seemingly endless time " "on the python-dev mailing list and kept up-to-date by Skip Montanaro." msgstr "" +"串列綜合運算的概念最初來自函式程式設計語言 Haskell (https://www.haskell.org)。" +"Greg Ewing 最有效地主張將它們加入 Python,並撰寫了最初的串列綜合運算補丁,然" +"後在 python-dev 郵件列表上討論了好久好久,後來由 Skip Montanaro 持續更新。" #: ../../whatsnew/2.0.rst:349 msgid "Augmented Assignment" -msgstr "" +msgstr "擴增賦值(Augmented Assignment)" #: ../../whatsnew/2.0.rst:351 msgid "" @@ -539,6 +687,9 @@ msgid "" "value of the variable ``a`` by 2, equivalent to the slightly lengthier ``a " "= a + 2``." msgstr "" +"擴增賦值運算子是另一個長期被要求的功能,已加入 Python 2.0。擴增賦值運算子包" +"括 ``+=``、``-=``、``*=`` 等等。例如陳述式 ``a += 2`` 將變數 ``a`` 的值增" +"加 2,等同於稍長的 ``a = a + 2``。" #: ../../whatsnew/2.0.rst:356 msgid "" @@ -549,6 +700,11 @@ msgid "" "following :class:`!Number` class stores a number and supports using += to " "create a new instance with an incremented value." msgstr "" +"支援的賦值運算子完整清單是 ``+=``、``-=``、``*=``、``/=``、``%=``、``**=``、" +"``&=``、``|=``、``^=``、``>>=`` 和 ``<<=``。Python 類別可以透過定義名為 " +":meth:`!__iadd__`、:meth:`!__isub__` 等方法來覆寫擴增賦值運算子。例如,以下" +"的 :class:`!Number` 類別儲存一個數字,並支援使用 += 來建立一個具有增加值的新" +"實例。" #: ../../whatsnew/2.0.rst:367 msgid "" @@ -562,6 +718,15 @@ msgid "" "n += 3\n" "print n.value" msgstr "" +"class Number:\n" +" def __init__(self, value):\n" +" self.value = value\n" +" def __iadd__(self, increment):\n" +" return Number( self.value + increment)\n" +"\n" +"n = Number(5)\n" +"n += 3\n" +"print n.value" #: ../../whatsnew/2.0.rst:377 msgid "" @@ -570,6 +735,8 @@ msgid "" "value; this return value is bound as the new value of the variable on the " "left-hand side." msgstr "" +":meth:`!__iadd__` 特殊方法會以增量值被呼叫,並應回傳一個具有適當修改值的新實" +"例;這個回傳值會被繫結為左側變數的新值。" #: ../../whatsnew/2.0.rst:381 msgid "" @@ -578,10 +745,13 @@ msgid "" "Perl, and PHP also support them. The augmented assignment patch was " "implemented by Thomas Wouters." msgstr "" +"擴增賦值運算子最初是在 C 程式語言中引入的,大多數源自 C 的語言,如 " +":program:`awk`、C++、Java、Perl 和 PHP 也支援它們。擴增指定的補丁由 Thomas " +"Wouters 實作。" #: ../../whatsnew/2.0.rst:390 msgid "String Methods" -msgstr "" +msgstr "字串方法" #: ../../whatsnew/2.0.rst:392 msgid "" @@ -593,6 +763,11 @@ msgid "" "string.replace`, which takes 3 string arguments, that means eight possible " "permutations, and correspondingly complicated code." msgstr "" +"到目前為止,字串操作功能都在 :mod:`string` 模組中,它通常是用 C 編寫的 " +":mod:`!strop` 模組的前端。Unicode 的加入給 :mod:`!strop` 模組帶來了困難,因" +"為所有函式都需要為了接受 8 位元或 Unicode 字串而重寫。對於像 :func:`!" +"string.replace` 這樣接受 3 個字串引數的函式,這代表要處理八種可能的排列組合以及" +"相應複雜的程式碼。" #: ../../whatsnew/2.0.rst:400 msgid "" @@ -600,6 +775,8 @@ msgid "" "manipulation functionality available through methods on both 8-bit strings " "and Unicode strings. ::" msgstr "" +"不過 Python 2.0 將問題推給字串型別,使字串操作功能可透過 8 位元字串和 " +"Unicode 字串的方法使用。 ::" #: ../../whatsnew/2.0.rst:404 msgid "" @@ -624,12 +801,15 @@ msgid "" "methods return new strings, and do not modify the string on which they " "operate." msgstr "" +"有一件事沒有改變,儘管有一個值得注意的愚人節玩笑,那就是 Python 字串是不可變" +"的。因此,字串方法會回傳新字串,而不會修改它們所操作的字串。" #: ../../whatsnew/2.0.rst:415 msgid "" "The old :mod:`string` module is still around for backwards compatibility, " "but it mostly acts as a front-end to the new string methods." msgstr "" +"舊的 :mod:`string` 模組為了向後相容仍然保留,但它主要充當新字串方法的前端。" #: ../../whatsnew/2.0.rst:418 msgid "" @@ -638,6 +818,9 @@ msgid "" "endswith`. ``s.startswith(t)`` is equivalent to ``s[:len(t)] == t``, while " "``s.endswith(t)`` is equivalent to ``s[-len(t):] == t``." msgstr "" +"有兩個方法在 2.0 之前的版本中沒有對應功能::meth:`!startswith` 和 :meth:`!endswith`," +"不過它們在 JPython 中已經存在了一段時間。``s.startswith(t)`` " +"等同於 ``s[:len(t)] == t``,而 ``s.endswith(t)`` 等同於 ``s[-len(t):] == t``。" #: ../../whatsnew/2.0.rst:423 msgid "" @@ -647,10 +830,13 @@ msgid "" "old :mod:`string` module, with the arguments reversed. In other words, " "``s.join(seq)`` is equivalent to the old ``string.join(seq, s)``." msgstr "" +"另一個值得特別提及的方法是 :meth:`!join`。字串的 :meth:`!join` 方法接收一個參" +"數,即字串序列,等同於舊 :mod:`string` 模組中的 :func:`!string.join` 函式,但" +"引數順序相反。換句話說,``s.join(seq)`` 等同於舊的 ``string.join(seq, s)``。" #: ../../whatsnew/2.0.rst:433 msgid "Garbage Collection of Cycles" -msgstr "" +msgstr "循環的垃圾回收" #: ../../whatsnew/2.0.rst:435 msgid "" @@ -661,6 +847,10 @@ msgid "" "no longer accessible, since you need to have a reference to an object to " "access it, and if the count is zero, no references exist any longer." msgstr "" +"Python 的 C 實作使用參照計數來實作垃圾回收。每個 Python 物件都維護一個指向自" +"身的參照數量計數,並在建立或銷毀參照時調整該計數。一旦參照計數達到零,該物件" +"就不再可存取,因為你需要有物件的參照才能存取它,如果計數為零,就表示不再有任" +"何參照存在。" #: ../../whatsnew/2.0.rst:442 msgid "" @@ -671,18 +861,24 @@ msgid "" "doesn't realise that objects are no longer accessible, resulting in a memory " "leak. This happens when there are cycles of references." msgstr "" +"參照計數有一些不錯的特性:它易於理解和實作,而且產生的實作具有可攜性、相" +"當快速,並且能與其他有實作自己的記憶體處理方案的函式庫良好配合。參照計數的主要問" +"題是它有時無法意識到物件已不再可存取,導致記憶體洩漏。這種情況發生在存在參照" +"循環時。" #: ../../whatsnew/2.0.rst:449 msgid "" "Consider the simplest possible cycle, a class instance which has a " "reference to itself::" -msgstr "" +msgstr "考慮最簡單的循環情況,一個類別實例具有對自身的參照: ::" #: ../../whatsnew/2.0.rst:452 msgid "" "instance = SomeClass()\n" "instance.myself = instance" msgstr "" +"instance = SomeClass()\n" +"instance.myself = instance" #: ../../whatsnew/2.0.rst:455 msgid "" @@ -690,6 +886,8 @@ msgid "" "``instance`` is 2; one reference is from the variable named ``'instance'``, " "and the other is from the ``myself`` attribute of the instance." msgstr "" +"執行上述兩行程式碼後,``instance`` 的參照計數為 2;一個參照來自名為 " +"``'instance'`` 的變數,另一個來自實例的 ``myself`` 屬性。" #: ../../whatsnew/2.0.rst:459 msgid "" @@ -700,6 +898,10 @@ msgid "" "objects can participate in a cycle if they have references to each other, " "causing all of the objects to be leaked." msgstr "" +"如果下一行程式碼是 ``del instance``,會發生什麼事?``instance`` 的參照計數減" +"少 1,所以它的參照計數變成 1;``myself`` 屬性中的參照仍然存在。然而該實例已經" +"無法透過 Python 程式碼存取,它可以被刪除。如果多個物件互相參照,它們就可以形" +"成循環,導致所有這些物件都被洩漏。" #: ../../whatsnew/2.0.rst:466 msgid "" @@ -709,6 +911,9 @@ msgid "" "collection, obtain debugging statistics, and tuning the collector's " "parameters." msgstr "" +"Python 2.0 透過定期執行循環偵測演算法來修復這個問題,該演算法會尋找不可存取的" +"循環並刪除涉及的物件。新的 :mod:`gc` 模組提供了執行垃圾回收、取得偵錯統計資訊" +"和調整回收器參數的函式。" #: ../../whatsnew/2.0.rst:471 msgid "" @@ -723,6 +928,12 @@ msgid "" "buggy, by specifying the :option:`!--without-cycle-gc` switch when running " "the :program:`configure` script." msgstr "" +"執行循環偵測演算法需要一些時間,因此會產生一些額外的開銷。希望在使用 2.0 得到" +"循環回收的經驗後,Python 2.1 將能夠仔細調整以最小化這些開銷。目前因為基準測試很棘" +"手所以還不清楚會損失多少效能,而且關鍵取決於程式建立和銷毀物件的頻率。" +"如果即便是微小的速度損失你也都無法承受,或者懷疑循環回收機制有誤,可以在編譯 " +"Python 時停用循環偵測,方式為執行 :program:`configure` 腳本時指定 :option:`!--without-" +"cycle-gc` 開關。" #: ../../whatsnew/2.0.rst:482 msgid "" @@ -736,10 +947,16 @@ msgid "" "threads titled \"Reference cycle collection for Python\" and \"Finalization " "again\"." msgstr "" +"多人處理了這個問題並為解決方案做出了貢獻。循環偵測方法的早期實作由 Toby " +"Kelsey 編寫。目前的演算法是 Eric Tiedemann 在訪問 CNRI 時建議的,Guido van " +"Rossum 和 Neil Schemenauer 編寫了兩個不同的實作,後來由 Neil 整合起來。也有許多人" +"在過程中提供了建議;python-dev 郵件列表的 2000 年 3 月存檔包含了大部分相關討" +"論,特別是標題為 \"Reference cycle collection for Python\" 和 \"Finalization " +"again\" 的討論串。" #: ../../whatsnew/2.0.rst:495 msgid "Other Core Changes" -msgstr "" +msgstr "其他核心變更" #: ../../whatsnew/2.0.rst:497 msgid "" @@ -747,10 +964,12 @@ msgid "" "functions. None of the changes are very far-reaching, but they're handy " "conveniences." msgstr "" +"對 Python 的語法和內建函式進行了各種小幅變更。這些變更的影響不大,但它" +"們是便利的功能。" #: ../../whatsnew/2.0.rst:502 msgid "Minor Language Changes" -msgstr "" +msgstr "次要語言變更" #: ../../whatsnew/2.0.rst:504 msgid "" @@ -763,6 +982,11 @@ msgid "" "and clearer way to achieve the same effect. This syntax is symmetrical with " "the syntax for defining functions::" msgstr "" +"新的語法使得使用引數元組和/或關鍵字引數字典呼叫給定函式更加方便。在 Python " +"1.5 及更早版本中,你會使用 :func:`!apply` 內建函式:``apply(f, args, kw)`` 使" +"用引數元組 *args* 和字典 *kw* 中的關鍵字引數來呼叫函式 :func:`!f`。" +":func:`!apply` 在 2.0 中仍然相同,但多虧了 Greg Ewing 的補丁,``f(*args, " +"**kw)`` 是達成相同效果的更簡短、更清晰的方式。此語法與定義函式的語法對稱: ::" #: ../../whatsnew/2.0.rst:513 msgid "" @@ -771,6 +995,10 @@ msgid "" " # kw is a dictionary of keyword args\n" " ..." msgstr "" +"def f(*args, **kw):\n" +" # args 是位置引數的元組,\n" +" # kw 是關鍵字引數的字典\n" +" ..." #: ../../whatsnew/2.0.rst:518 msgid "" @@ -782,10 +1010,15 @@ msgid "" "``sys.stdout`` and then restore the old value. For sending output to " "standard error, it's much easier to write this::" msgstr "" +"現在可以透過在 ``print`` 後面加上 ``>> file`` 來將 ``print`` 陳述式的輸出導向" +"至類檔案物件,類似於 Unix shell 中的重新導向運算子。以前你必須使用類檔案物件" +"的 :meth:`!write` 方法,這缺乏 ``print`` 的便利性和簡潔性,或者你可以為 " +"``sys.stdout`` 指定新值然後恢復舊值。對於將輸出發送到標準錯誤,這樣寫簡單多" +"了: ::" #: ../../whatsnew/2.0.rst:526 msgid "print >> sys.stderr, \"Warning: action field not supplied\"" -msgstr "" +msgstr "print >> sys.stderr, \"Warning: action field not supplied\"" #: ../../whatsnew/2.0.rst:528 msgid "" @@ -793,6 +1026,8 @@ msgid "" "module as name`` or ``from module import name as othername``. The patch was " "submitted by Thomas Wouters." msgstr "" +"現在可以在引入模組時重新命名它們,使用語法 ``import module as name`` 或 " +"``from module import name as othername``。該補丁由 Thomas Wouters 提交。" #: ../../whatsnew/2.0.rst:532 msgid "" @@ -802,6 +1037,10 @@ msgid "" "which inserts the :func:`str` of its argument. For example, ``'%r %s' % " "('abc', 'abc')`` returns a string containing ``'abc' abc``." msgstr "" +"使用 ``%`` 運算子時新增了一個新的格式樣式;'%r' 將插入其引數的 :func:`repr`。" +"這也是出於對稱性考量而新增的,這次是與現有的 '%s' 格式樣式對稱,後者會插入其" +"引數的 :func:`str`。例如,``'%r %s' % ('abc', 'abc')`` 回傳一個包含 " +"``'abc' abc`` 的字串。" #: ../../whatsnew/2.0.rst:538 msgid "" @@ -815,6 +1054,12 @@ msgid "" "built-in objects written in C can define what :keyword:`!in` means for them " "via a new slot in the sequence protocol." msgstr "" +"以前沒有辦法實作一個覆寫 Python 內建 :keyword:`in` 運算子並實作自訂版本的類" +"別。如果 *obj* 存在於序列 *seq* 中,``obj in seq`` 回傳 true;Python 透過簡單" +"地嘗試序列的每個索引來計算這個,直到找到 *obj* 或遇到 :exc:`IndexError`。" +"Moshe Zadka 貢獻了一個補丁,新增了一個 :meth:`!__contains__` 魔術方法,用於提" +"供 :keyword:`!in` 的自訂實作。此外,用 C 編寫的新內建物件可以透過序列協定中的" +"新插槽來定義 :keyword:`!in` 對它們的意義。" #: ../../whatsnew/2.0.rst:547 msgid "" @@ -825,6 +1070,10 @@ msgid "" "and crashed; Jeremy Hylton rewrote the code to no longer crash, producing a " "useful result instead. For example, after this code::" msgstr "" +"早期版本的 Python 使用遞迴演算法來刪除物件。深度巢狀的資料結構可能會導致直譯" +"器填滿 C 堆疊並當機;Christian Tismer 重寫了刪除邏輯來修復這個問題。比較遞迴物件會" +"造成無限遞迴並導致崩潰 (crash);Jeremy Hylton 重寫了程式碼使其不再崩潰,而是產" +"生有用的結果。例如在這段程式碼之後: ::" #: ../../whatsnew/2.0.rst:554 msgid "" @@ -833,6 +1082,10 @@ msgid "" "a.append(a)\n" "b.append(b)" msgstr "" +"a = []\n" +"b = []\n" +"a.append(a)\n" +"b.append(b)" #: ../../whatsnew/2.0.rst:559 msgid "" @@ -845,6 +1098,11 @@ msgid "" "even if a user-defined :meth:`!__cmp__` method encountered an error, since " "the resulting exception would simply be silently swallowed." msgstr "" +"``a==b`` 的比較會回傳 true,因為這兩個遞迴資料結構是同構的 (isomorphic)。請參閱 " +"python-dev 郵件列表 2000 年 4 月存檔中的 \"trashcan and PR#7\" 討論串,以了解" +"最後決定此實作的討論和一些有用的相關連結。請注意,比較現在也可以引發例外。在早期版本的 " +"Python 中,像 ``cmp(a,b)`` 這樣的比較操作總是會產生答案,即使使用者定義的 " +":meth:`!__cmp__` 方法遇到錯誤,因為產生的例外會被默默地吞掉。" #: ../../whatsnew/2.0.rst:571 msgid "" @@ -855,6 +1113,11 @@ msgid "" "also supports Windows CE; see the Python CE page at https://" "pythonce.sourceforge.net/ for more information." msgstr "" +"已經完成了將 Python 移植到 Itanium 處理器上的 64 位元 Windows 的工作,主要由 " +"ActiveState 的 Trent Mick 完成。(令人困惑的是,``sys.platform`` 在 Win64 上" +"仍然是 ``'win32'``,因為似乎為了方便移植,MS Visual C++ 在 Itanium 上將程式碼" +"視為 32 位元。)PythonWin 也支援 Windows CE;詳見 https://pythonce." +"sourceforge.net/ 上的 Python CE 頁面以取得更多資訊。" #: ../../whatsnew/2.0.rst:577 msgid "" @@ -863,6 +1126,9 @@ msgid "" "suffix=.x\". Consult the README in the Python source distribution for more " "instructions." msgstr "" +"另一個新平台是 Darwin/MacOS X;Python 2.0 中包含了對它的初步支援。如果你指定 " +"\"configure --with-dyld --with-suffix=.x\",動態載入就可以運作。請參閱 Python " +"原始碼發布板中的 README 以取得更多指示。" #: ../../whatsnew/2.0.rst:581 msgid "" @@ -875,6 +1141,12 @@ msgid "" "subclass of :exc:`NameError`, so any existing code that " "expects :exc:`NameError` to be raised should still work. ::" msgstr "" +"程式碼中的區域變數在被指定值前就被參照的話,經常引發令人困惑的 :exc:`NameError` 例外," +"這個 Python 的缺陷有被嘗試改善。拿以下程式碼為例,它於 1.5.2 和 2.0 中都會" +"在 ``print`` 陳述式上引發例外;在 1.5.2 中會引發 :exc:`NameError` 例外,而 " +"2.0 會引發新的 :exc:`UnboundLocalError` 例外。:exc:`UnboundLocalError` 是 " +":exc:`NameError` 的子類別,所以任何預期會引發 :exc:`NameError` 的現有程式碼應" +"該仍然可以運作。 ::" #: ../../whatsnew/2.0.rst:590 msgid "" @@ -894,10 +1166,12 @@ msgid "" "introduced. They're both subclasses of :exc:`SyntaxError`, and are raised " "when Python code is found to be improperly indented." msgstr "" +"引入了兩個新例外,:exc:`TabError` 和 :exc:`IndentationError`。它們都是 " +":exc:`SyntaxError` 的子類別,當發現 Python 程式碼縮排不正確時就會被引發。" #: ../../whatsnew/2.0.rst:601 msgid "Changes to Built-in Functions" -msgstr "" +msgstr "內建函式的變更" #: ../../whatsnew/2.0.rst:603 msgid "" @@ -908,6 +1182,10 @@ msgid "" "``None`` if the sequences aren't all of the same length, while :func:`zip` " "truncates the returned list to the length of the shortest argument sequence." msgstr "" +"新增了一個內建函式 ``zip(seq1, seq2, ...)``。:func:`zip` 回傳一個元組串" +"列,其中每個元組包含來自每個引數序列的第 i 個元素。:func:`zip` 和 " +"``map(None, seq1, seq2)`` 之間的區別是,如果序列的長度不同,:func:`map` 會用 " +"``None`` 填充序列,而 :func:`zip` 會將回傳的串列截斷為最短引數序列的長度。" #: ../../whatsnew/2.0.rst:610 msgid "" @@ -917,6 +1195,10 @@ msgid "" "a :exc:`TypeError` exception with the message \"can't convert non-string " "with explicit base\"." msgstr "" +"當第一個引數是字串時,:func:`int` 和 :func:`!long` 函式現在接受可選的 " +"\"base\" 參數。``int('123', 10)`` 回傳 123,而 ``int('123', 16)`` 回傳 291。" +"``int(123, 16)`` 會引發 :exc:`TypeError` 例外,訊息為 \"can't convert non-string " +"with explicit base\"。" #: ../../whatsnew/2.0.rst:616 msgid "" @@ -926,6 +1208,11 @@ msgid "" "``sys.version_info`` would be ``(2, 0, 1, 'beta', 1)``. *level* is a string " "such as ``\"alpha\"``, ``\"beta\"``, or ``\"final\"`` for a final release." msgstr "" +"在 :mod:`sys` 模組中新增了一個包含更詳細版本資訊的新變數。" +"``sys.version_info`` 是一個元組 ``(major, minor, micro, level, serial)``。例" +"如,在假設的 2.0.1beta1 中,``sys.version_info`` 會是 ``(2, 0, 1, 'beta', " +"1)``。*level* 是一個字串,如 ``\"alpha\"``、``\"beta\"`` 或最終版本的 " +"``\"final\"``。" #: ../../whatsnew/2.0.rst:622 msgid "" @@ -935,6 +1222,10 @@ msgid "" "as :meth:`!get` would do, and also inserts it into the dictionary as the " "value for *key*. Thus, the following lines of code::" msgstr "" +"字典有一個奇特的新方法 ``setdefault(key, default)``,其行為類似於現有的 " +":meth:`!get` 方法。然而如果鍵不存在,:meth:`!setdefault` 既會像 " +":meth:`!get` 一樣回傳 *default* 的值,也會將其作為 *key* 的值插入字典。因此," +"以下幾行程式碼: ::" #: ../../whatsnew/2.0.rst:628 msgid "" @@ -951,7 +1242,7 @@ msgstr "" #: ../../whatsnew/2.0.rst:633 msgid "" "can be reduced to a single ``return dict.setdefault(key, [])`` statement." -msgstr "" +msgstr "可以簡化為單一的 ``return dict.setdefault(key, [])`` 陳述式。" #: ../../whatsnew/2.0.rst:635 msgid "" @@ -963,10 +1254,15 @@ msgid "" "default value is 1000, and a rough maximum value for a given platform can be " "found by running a new script, :file:`Misc/find_recursionlimit.py`." msgstr "" +"直譯器會設定最大遞迴深度,以便在填滿 C 堆疊並導致核心傾印 (core dump) 或 GPF 之前捕獲失控" +"的遞迴。以前這個限制在編譯 Python 時就固定了,但在 2.0 中最大遞迴深度可以使" +"用 :func:`sys.getrecursionlimit` 和 :func:`sys.setrecursionlimit` 來讀取和修" +"改。預設值是 1000,可以透過執行新的腳本 :file:`Misc/find_recursionlimit.py` " +"來找到給定平台約略的最大值。" #: ../../whatsnew/2.0.rst:647 msgid "Porting to 2.0" -msgstr "" +msgstr "移植到 2.0" #: ../../whatsnew/2.0.rst:649 msgid "" @@ -977,6 +1273,10 @@ msgid "" "always be avoided. This section lists the changes in Python 2.0 that may " "cause old Python code to break." msgstr "" +"新的 Python 版本努力與先前的版本相容,而且過去記錄維持很好。然而有些變更被認為只是" +"足夠有用而已,通常是因為它們修正了後來證明是完全錯誤的初始設計決策,因此並不總是" +"能避免破壞向後相容性。本節列出了 Python 2.0 中可能導致舊 Python 程式碼出問題" +"的變更。" #: ../../whatsnew/2.0.rst:656 msgid "" @@ -990,6 +1290,13 @@ msgid "" "The fix is to simply add an extra set of parentheses to pass both values as " "a tuple: ``L.append( (1,2) )``." msgstr "" +"可能會破壞最多程式碼的變更是收緊某些方法接受的引數。某些方法會接受多個引數並" +"將它們視為元組,特別是各種串列方法如 :meth:`~list.append` 和 " +":meth:`~list.insert`。在早期版本的 Python 中,如果 ``L`` 是一個串列," +"``L.append( 1,2 )`` 會將元組 ``(1,2)`` 附加到串列中。在 Python 2.0 中,這會導" +"致引發 :exc:`TypeError` 例外,訊息為:'append requires exactly 1 argument; 2 " +"given'。修正方法單純是加一組額外的括號來將兩個值作為元組傳遞:``L.append(" +" (1,2) )``。" #: ../../whatsnew/2.0.rst:666 msgid "" @@ -1002,6 +1309,11 @@ msgid "" "preprocessor symbol ``NO_STRICT_LIST_APPEND`` to preserve the old behaviour; " "this isn't recommended." msgstr "" +"這些方法的早期版本更寬容,因為它們使用 Python C 介面中的舊函式來剖析引數;2.0 " +"將它們現代化為使用 :c:func:`PyArg_ParseTuple`,即目前的引數剖析函式,它提供" +"更有幫助的錯誤訊息並將多引數呼叫視為錯誤。如果你必須使用 2.0 但無法修正你" +"的程式碼,你可以編輯 :file:`Objects/listobject.c` 並定義前處理器 (preprocessor) 符號 " +"``NO_STRICT_LIST_APPEND`` 來保留舊行為;但不建議這樣做。" #: ../../whatsnew/2.0.rst:674 msgid "" @@ -1018,6 +1330,14 @@ msgid "" "marked as deprecated; it *will* be tightened up again in a future Python " "version." msgstr "" +":mod:`socket` 模組中的某些函式在這方面仍然很寬容。例如 " +"``socket.connect( ('hostname', 25) )`` 仍是傳遞一個代表 IP 位址的元" +"組的正確形式,但 ``socket.connect('hostname', 25)`` 也可以運作。:meth:`socket.connect_ex " +"` 和 :meth:`socket.bind ` 同樣寬" +"鬆。2.0alpha1 收緊了這些函式,但因為文件實際上使用了錯誤的多引數形式,許多人" +"寫的程式碼會因更嚴格的檢查而出問題。GvR 考慮公眾反應而撤回了變更,所以 " +":mod:`socket` 模組文件因此被修正了,多引數形式只是被標記為已棄用;它\\ *將會*\\ " +"在未來的 Python 版本中再次被收緊。" #: ../../whatsnew/2.0.rst:685 msgid "" @@ -1026,6 +1346,9 @@ msgid "" "the lowest 8 bits of the result, so ``\\x123456`` was equivalent to " "``\\x56``." msgstr "" +"字串字面值中的 ``\\x`` 跳脫現在正好取 2 個十六進位數字。以前它會消耗 'x' 後面" +"的所有十六進位數字並取結果的最低 8 位元,所以 ``\\x123456`` 等同於 " +"``\\x56``。" #: ../../whatsnew/2.0.rst:689 msgid "" @@ -1035,6 +1358,10 @@ msgid "" "error message was just the missing attribute name ``eggs``, and code written " "to take advantage of this fact will break in 2.0." msgstr "" +":exc:`AttributeError` 和 :exc:`NameError` 例外有了更友善的錯誤訊息,其文字會類" +"似於 ``'Spam' instance has no attribute 'eggs'`` 或 ``name 'eggs' is not " +"defined``。以前錯誤訊息只是缺少的屬性名稱 ``eggs``,利用這一事實編寫的程式碼" +"在 2.0 中會出問題。" #: ../../whatsnew/2.0.rst:695 msgid "" @@ -1052,6 +1379,15 @@ msgid "" "the ``%`` operator (``%d``, ``%i``, ``%x``, etc.). For example, ``\"%d\" % " "2L**64`` will produce the string ``18446744073709551616``." msgstr "" +"已經完成了一些使整數和長整數更具互換性的工作。在 1.5.2 中,為 Solaris 新增了大" +"型檔案支援,允許讀取大於 2 GiB 的檔案;這使得檔案物件的 :meth:`!tell` 方法" +"改為回傳長整數而不是一般整數。某些程式碼會將兩個檔案偏移量相減並嘗試使用結果來乘" +"以序列或切片字串,但這會引發 :exc:`TypeError`。在 2.0 中,長整數可以用於乘以" +"或切片序列,它會按你直覺預期的方式運作;``3L * 'abc'`` 會產生 'abcabcabc'、" +"``(0,1,2,3)[2L:4L]`` 會產生 (2,3)。長整數也可以用於以前只接受整數的各種情況,例" +"如檔案物件的 :meth:`!seek` 方法,以及 ``%`` 運算子支援的格式(``%d``、" +"``%i``、``%x`` 等)。例如 ``\"%d\" % 2L**64`` 會產生字串 " +"``18446744073709551616``。" #: ../../whatsnew/2.0.rst:709 msgid "" @@ -1063,6 +1399,10 @@ msgid "" "which does ``str(longval)[:-1]`` and assumes the 'L' is there, will now lose " "the final digit." msgstr "" +"所有長整數變更中最微妙的是長整數的 :func:`str` 不再有尾隨的 'L' 字元,儘管 " +":func:`repr` 仍然包含它。'L' 讓許多想要印出看起來像普通整數的長整數的人感到惱" +"火,因為他們必須特意去掉這個字元。在 2.0 中這不再是問題,但執行 " +"``str(longval)[:-1]`` 並假設 'L' 存在的程式碼現在會丟失最後一個數字。" #: ../../whatsnew/2.0.rst:717 msgid "" @@ -1074,6 +1414,11 @@ msgid "" "be represented exactly in binary, so ``repr(8.1)`` is " "``'8.0999999999999996'``, while str(8.1) is ``'8.1'``." msgstr "" +"取浮點數的 :func:`repr` 現在使用與 :func:`str` 不同的格式化精度。:func:`repr` " +"對 C 的 :func:`!sprintf` 使用 ``%.17g`` 格式字串,而 :func:`str` 像以前一樣使" +"用 ``%.12g``。效果是對於某些數字,:func:`repr` 可能偶爾會顯示比 :func:`str` " +"更多的小數位。例如數字 8.1 無法用二進位精確表示,所以 ``repr(8.1)`` 是 " +"``'8.0999999999999996'``,而 str(8.1) 是 ``'8.1'``。" #: ../../whatsnew/2.0.rst:725 msgid "" @@ -1083,10 +1428,13 @@ msgid "" "standard exceptions was translated from Python to a built-in C module, " "written by Barry Warsaw and Fredrik Lundh." msgstr "" +"``-X`` 命令列選項已被移除,該選項會將所有標準例外轉換為字串而不是類別;現在標" +"準例外將始終是類別。包含標準例外的 :mod:`!exceptions` 模組已從 Python 翻譯為" +"內建的 C 模組,這由 Barry Warsaw 和 Fredrik Lundh 編寫。" #: ../../whatsnew/2.0.rst:741 msgid "Extending/Embedding Changes" -msgstr "" +msgstr "擴充/嵌入變更" #: ../../whatsnew/2.0.rst:743 msgid "" @@ -1095,6 +1443,8 @@ msgid "" "larger application. If you aren't dealing with Python's C API, you can " "safely skip this section." msgstr "" +"有些變更是在底層,只有編寫 C 擴充模組或將 Python 直譯器嵌入到較大應用程式中" +"的人才會注意到。如果你不處理 Python 的 C API,可以安全地跳過本節。" #: ../../whatsnew/2.0.rst:748 msgid "" @@ -1104,6 +1454,9 @@ msgid "" "built for Python 1.5.x due to how Windows DLLs work, so Python will raise an " "exception and the import will fail." msgstr "" +"Python C API 的版本號已增加,因此為 1.5.2 編譯的 C 擴充必須重新編譯才能與 " +"2.0 一起使用。在 Windows 上由於 Windows DLL 的運作方式,Python 2.0 無法引入" +"為 Python 1.5.x 建立的第三方擴充,因此 Python 會引發例外且引入會失敗。" #: ../../whatsnew/2.0.rst:754 msgid "" @@ -1113,6 +1466,10 @@ msgid "" "to remember to write code such as ``if type(obj) == myExtensionClass``, but " "can use the more natural ``if isinstance(obj, myExtensionClass)``." msgstr "" +"Jim Fulton 的 ExtensionClass 模組使用者會高興地發現掛鉤已被添加,使 " +"ExtensionClass 現在有被 :func:`isinstance` 和 :func:`issubclass` 支援。這意味著" +"你不再需要記得編寫像 ``if type(obj) == myExtensionClass`` 這樣的程式碼,而是" +"可以使用更自然的 ``if isinstance(obj, myExtensionClass)``。" #: ../../whatsnew/2.0.rst:760 msgid "" @@ -1124,6 +1481,11 @@ msgid "" "Include/ directory that held various portability hacks; they've been merged " "into a single file, :file:`Include/pyport.h`." msgstr "" +":file:`Python/importdl.c` 檔案以前是一堆 #ifdef 來支援許多不同平台上的動態載" +"入,這已被 Greg Stein 清理和重組。:file:`importdl.c` 現在相當小,平台特定的程式" +"碼已移至一系列 :file:`Python/dynload_\\*.c` 檔案中。有另一個清理工作:Include/ 目錄" +"中的許多 :file:`my\\*.h` 檔案包含各種為改善可攜性的 hack;它們已被合併到單一檔案 " +":file:`Include/pyport.h`。" #: ../../whatsnew/2.0.rst:768 msgid "" @@ -1134,6 +1496,10 @@ msgid "" "discussions during which the interface was hammered out, see the web " "archives of the 'patches' and 'python-dev' lists at python.org." msgstr "" +"Vladimir Marangozov 完成了備受期待的 malloc 重構,使 Python 直譯器可以輕鬆使用" +"自訂記憶體分配器而不是 C 的標準 :c:func:`malloc`。相關文件請閱讀 " +":file:`Include/pymem.h` 和 :file:`Include/objimpl.h` 中的註解。敲定介面的" +"冗長討論,請參閱 python.org 上 'patches' 和 'python-dev' 列表的網路存檔。" #: ../../whatsnew/2.0.rst:775 msgid "" @@ -1142,6 +1508,9 @@ msgid "" "Macintosh. Threading support using the user-space GNU ``pth`` library was " "also contributed." msgstr "" +"MacOS 的 GUSI 開發環境的近期版本支援了 POSIX 執行緒。因此,Python 的 POSIX 執行" +"緒支援現在可以在 Macintosh 上運作。也貢獻了有用到使用者空間 GNU ``pth`` 函式庫" +"的執行緒支援。" #: ../../whatsnew/2.0.rst:780 msgid "" @@ -1152,6 +1521,10 @@ msgid "" "as an unthreaded version; with the 2.0 changes, the difference is only 10%. " "These improvements were contributed by Yakov Markovitch." msgstr "" +"Windows 上的執行緒支援也得到了改進。Windows 支援僅在爭用情況 (contention) 下使用核心 " +"(kernel) 物件的執行緒鎖定;在沒有爭用的常見情況下,它們使用更簡單的函式,速度快一個數量級。" +"NT 上 Python 1.5.2 的執行緒版本比非執行緒版本慢兩倍;經過 2.0 的變更,差異只有 " +"10%。這些改進由 Yakov Markovitch 貢獻。" #: ../../whatsnew/2.0.rst:787 msgid "" @@ -1159,6 +1532,8 @@ msgid "" "requires an ANSI C compiler, and can no longer be done using a compiler that " "only supports K&R C." msgstr "" +"Python 2.0 的原始碼現在只使用 ANSI C 原型,因此編譯 Python 現在需要 ANSI C 編" +"譯器,不能再使用只支援 K&R C 的編譯器。" #: ../../whatsnew/2.0.rst:791 msgid "" @@ -1168,6 +1543,10 @@ msgid "" "who are generating Python code would run into this limit. A patch by " "Charles G. Waldman raises the limit from ``2**16`` to ``2**32``." msgstr "" +"以前 Python 虛擬機在其位元組碼中使用 16 位元數字,限制了原始檔的大小。特別" +"是這影響了 Python 原始碼中字面串列和字典的最大大小;偶爾生成 Python 程式碼" +"的人會遇到這個限制。Charles G. Waldman 的補丁將限制從 ``2**16`` 提高到 " +"``2**32``。" #: ../../whatsnew/2.0.rst:797 msgid "" @@ -1179,6 +1558,11 @@ msgid "" "and a third argument for the value to be assigned to the name. This third " "argument is, respectively, a Python object, a C long, or a C string." msgstr "" +"新增了三個便利函式,以用於在模組初始化時將常數加入模組的字典:" +":c:func:`PyModule_AddObject`、:c:func:`PyModule_AddIntConstant` 和 " +":c:func:`PyModule_AddStringConstant`。這些函式分別接受一個模組物件、一個包含" +"要新增名稱的以 null 結尾的 C 字串,以及一個用於指定給該名稱的值的第三個引數。" +"這第三個引數分別是 Python 物件、C long 或 C 字串。" #: ../../whatsnew/2.0.rst:805 msgid "" @@ -1186,10 +1570,12 @@ msgid "" "handlers. :c:func:`PyOS_getsig` gets a signal handler " "and :c:func:`PyOS_setsig` will set a new handler." msgstr "" +"為 Unix 風格的訊號處理程式新增了一個包裝器 API。:c:func:`PyOS_getsig` 會取得訊號" +"處理程式,:c:func:`PyOS_setsig` 會設定新的處理程式。" #: ../../whatsnew/2.0.rst:812 msgid "Distutils: Making Modules Easy to Install" -msgstr "" +msgstr "Distutils:讓模組安裝變簡單" #: ../../whatsnew/2.0.rst:814 msgid "" @@ -1202,6 +1588,11 @@ msgid "" "different extension packages, which made administering a Python installation " "something of a chore." msgstr "" +"在 Python 2.0 之前,安裝模組是一件繁瑣的事情 —— 沒有辦法自動找出 Python 安裝在" +"哪裡,或者擴充模組應該使用什麼編譯器選項。軟體作者必須經歷編輯 Makefile 和設" +"定檔的艱苦過程,而這些只真正適用於 Unix,使得 Windows 和 MacOS 不受支援。不同擴充套件" +"會有迥異的安裝方式,使得 Python 使用者們需要面對歧異度過高的各種安裝指南,使得管理 " +"Python 安裝成為一件苦差事。" #: ../../whatsnew/2.0.rst:822 msgid "" @@ -1218,6 +1609,12 @@ msgid "" "separating the build from the install, building or installing in non-default " "directories, and more." msgstr "" +"由 Greg Ward 領導的發布工具 SIG 建立了 Distutils,一個讓套件安裝更容易的系" +"統。它們構成了 ``distutils`` 套件,是 Python 標準函式庫新的部分。在最佳情況" +"下,從原始碼安裝 Python 模組只需要相同的步驟:首先你只需解壓縮 tarball 或 zip " +"檔案,然後執行 \"``python setup.py install``\",這就會自動偵測平台、識別編譯器、" +"編譯 C 擴充模組,並將發布板安裝到適當的目錄。可選的命令列引數提供對安裝過程的更多控制," +"distutils 套件提供了許多能夠覆寫預設值的地方 —— 將建置與安裝分開、在非預設目錄中建置或安裝等等。" #: ../../whatsnew/2.0.rst:834 msgid "" @@ -1225,6 +1622,8 @@ msgid "" "For the simple case, when the software contains only .py files, a " "minimal :file:`setup.py` can be just a few lines long::" msgstr "" +"為了使用 Distutils,你需要編寫一個 :file:`setup.py` 腳本。對於簡單的情況,當" +"軟體只包含 .py 檔案時,一個最小的 :file:`setup.py` 可能只有幾行: ::" #: ../../whatsnew/2.0.rst:838 msgid "" @@ -1240,7 +1639,7 @@ msgstr "" msgid "" "The :file:`setup.py` file isn't much more complicated if the software " "consists of a few packages::" -msgstr "" +msgstr "如果軟體由數個套件組成的話,:file:`setup.py` 檔案也不會複雜太多: ::" #: ../../whatsnew/2.0.rst:845 msgid "" @@ -1256,7 +1655,7 @@ msgstr "" msgid "" "A C extension can be the most complicated case; here's an example taken from " "the PyXML package::" -msgstr "" +msgstr "C 擴充可能是最複雜的情況;這是一個取自 PyXML 套件的範例: ::" #: ../../whatsnew/2.0.rst:852 msgid "" @@ -1297,12 +1696,19 @@ msgid "" "distribution formats such as Debian packages and Solaris :file:`.pkg` files " "are in various stages of development." msgstr "" +"Distutils 也可以建立原始碼和二進位發布板。透過 \"``python setup.py sdist``\" " +"執行的 \"sdist\" 命令會建立原始碼發布板,如 :file:`foo-1.0.tar.gz`。新" +"增命令並不困難,\"bdist_rpm\" 和 \"bdist_wininst\" 命令已被貢獻,分別用於建立軟體" +"的 RPM 發布板和 Windows 安裝程式。建立其他發行格式(如 Debian 套件和 Solaris " +":file:`.pkg` 檔案)的命令正處於不同的開發階段。" #: ../../whatsnew/2.0.rst:874 msgid "" "All this is documented in a new manual, *Distributing Python Modules*, that " "joins the basic set of Python documentation." msgstr "" +"所有這些都記錄在新的手冊 *Distributing Python Modules* 中,該手冊加入了 " +"Python 的基本文件集。" #: ../../whatsnew/2.0.rst:881 msgid "XML Modules" @@ -1322,6 +1728,14 @@ msgid "" "documentation or the source code for complete details. The Python XML SIG is " "also working on improved documentation." msgstr "" +"Python 1.5.2 包含了一個以 :mod:`!xmllib` 模組形式提供的簡單 XML 剖析器,其由 " +"Sjoerd Mullender 所貢獻。自 1.5.2 發布以來,兩種不同的 XML 處理介面變得常見:" +"SAX2(Simple API for XML 的第二版)提供了一個事件驅動的介面,它與 " +":mod:`!xmllib` 有些相似,而 DOM(Document Object Model,文件物件模型)提供了" +"一個基於樹狀結構的介面,將 XML 文件轉換為可以遍歷和修改的節點樹。Python 2.0 " +"包含了 SAX2 介面和精簡的 DOM 介面,作為 :mod:`xml` 套件的一部分。這裡我們將簡" +"要概述這些新介面;請查閱 Python 文件或原始碼以取得完整詳情。Python XML SIG 也" +"正在改進文件。" #: ../../whatsnew/2.0.rst:897 msgid "SAX2 Support" @@ -1339,6 +1753,12 @@ msgid "" "the :meth:`~xml.sax.handler.ContentHandler.characters` method is called for " "every chunk of character data, and so forth." msgstr "" +"SAX 定義了一個用於剖析 XML 的事件驅動介面。要使用 SAX,你必須編寫一個 SAX 處" +"理程式類別。處理程式類別繼承自 SAX 提供的各種類別,並覆寫各種方法,然後這些方" +"法會被 XML 剖析器呼叫。例如,:meth:`~xml.sax.handler.ContentHandler.startElement` " +"和 :meth:`~xml.sax.handler.ContentHandler.endElement` 方法會在剖析器遇到每個開" +"始標籤和結束標籤時被呼叫,:meth:`~xml.sax.handler.ContentHandler.characters` " +"方法會在每個字元資料區塊時被呼叫,依此類推。" #: ../../whatsnew/2.0.rst:907 msgid "" @@ -1348,6 +1768,9 @@ msgid "" "class can get very complicated if you're trying to modify the document " "structure in some elaborate way." msgstr "" +"事件驅動方法的優點是整個文件不必在任何時候都駐留在記憶體中,如果你正在處理非" +"常龐大的文件,這一點會很重要。然而如果你試圖以某種複雜的方式修改文件結構,編" +"寫 SAX 處理程式類別可能會變得非常複雜。" #: ../../whatsnew/2.0.rst:913 msgid "" @@ -1355,6 +1778,8 @@ msgid "" "message for every starting and ending tag, and then parses the " "file :file:`hamlet.xml` using it::" msgstr "" +"例如這個定義了一個處理程式的小範例程式,它會為每個開始標籤和結束標籤印出訊" +"息,然後使用它來剖析檔案 :file:`hamlet.xml`: ::" #: ../../whatsnew/2.0.rst:917 msgid "" @@ -1377,12 +1802,32 @@ msgid "" "# Parse a file!\n" "parser.parse( 'hamlet.xml' )" msgstr "" +"from xml import sax\n" +"\n" +"class SimpleHandler(sax.ContentHandler):\n" +" def startElement(self, name, attrs):\n" +" print 'Start of element:', name, attrs.keys()\n" +"\n" +" def endElement(self, name):\n" +" print 'End of element:', name\n" +"\n" +"# 建立剖析器物件\n" +"parser = sax.make_parser()\n" +"\n" +"# 告訴它使用哪個處理程式\n" +"handler = SimpleHandler()\n" +"parser.setContentHandler( handler )\n" +"\n" +"# 剖析檔案!\n" +"parser.parse( 'hamlet.xml' )" #: ../../whatsnew/2.0.rst:936 msgid "" "For more information, consult the Python documentation, or the XML HOWTO at " "https://pyxml.sourceforge.net/topics/howto/xml-howto.html." msgstr "" +"如需更多資訊,請查閱 Python 文件,或位於 https://pyxml.sourceforge.net/" +"topics/howto/xml-howto.html 的 XML HOWTO。" #: ../../whatsnew/2.0.rst:941 msgid "DOM Support" @@ -1399,6 +1844,11 @@ msgid "" "access element and attribute values, insert and delete nodes, and convert " "the tree back into XML." msgstr "" +"文件物件模型是 XML 文件的樹狀表示法。頂層 :class:`!Document` 實例是樹的根,有" +"一個子節點是頂層 :class:`!Element` 實例。這個 :class:`!Element` 有子節點代表" +"字元資料和任何子元素,這些子元素可能又有自己的子節點,依此類推。使用 DOM 你可" +"以用任何你喜歡的方式遍歷結果樹、存取元素和屬性值、插入和刪除節點,並將樹轉換" +"回 XML。" #: ../../whatsnew/2.0.rst:951 msgid "" @@ -1409,6 +1859,10 @@ msgid "" "producing XML output than simply writing ````...\\ ```` to a " "file." msgstr "" +"DOM 對於修改 XML 文件很有用,因為你可以建立 DOM 樹、透過新增節點或重新排列子" +"樹來修改它,然後產生新的 XML 文件作為輸出。你也可以手動建構 DOM 樹並將其轉換" +"為 XML,這可能比簡單地將 ````...\\ ```` 寫入檔案更靈活地產生 XML " +"輸出。" #: ../../whatsnew/2.0.rst:957 msgid "" @@ -1418,6 +1872,9 @@ msgid "" "and :func:`!parseString` convenience functions are provided for generating a " "DOM tree::" msgstr "" +"Python 附帶的 DOM 實作位於 :mod:`xml.dom.minidom` 模組中。它是 Level 1 DOM 的" +"輕量級實作,支援 XML 命名空間。它提供了 :func:`!parse` 和 :func:`!parseString` " +"便利函式來產生 DOM 樹: ::" #: ../../whatsnew/2.0.rst:962 msgid "" @@ -1438,6 +1895,12 @@ msgid "" "and :class:`!Document` instances have a method to find all child elements " "with a given tag name. Continuing from the previous 2-line example::" msgstr "" +"``doc`` 是一個 :class:`!Document` 實例。:class:`!Document` 與所有其他 DOM 類" +"別(如 :class:`!Element` 和 :class:`Text`)一樣,是 :class:`!Node` 基礎類別的" +"子類別。因此 DOM 樹中的所有節點都支援某些共同方法,例如 :meth:`!toxml` 會回傳" +"一個包含節點及其子節點的 XML 表示的字串。每個類別也有自己的特殊方法;例如 " +":class:`!Element` 和 :class:`!Document` 實例有一個方法可以找到所有具有給定標" +"籤名稱的子元素。從前面的 2 行範例繼續: ::" #: ../../whatsnew/2.0.rst:974 msgid "" @@ -1451,7 +1914,7 @@ msgstr "" #: ../../whatsnew/2.0.rst:978 msgid "For the *Hamlet* XML file, the above few lines output::" -msgstr "" +msgstr "對於 *Hamlet* XML 檔案,以上幾行會輸出: ::" #: ../../whatsnew/2.0.rst:980 msgid "" @@ -1467,6 +1930,8 @@ msgid "" "and its children can be easily modified by deleting, adding, or removing " "nodes::" msgstr "" +"文件的根元素可透過 ``doc.documentElement`` 取得,其子節點可以透過刪除、新增或" +"移除節點輕鬆修改: ::" #: ../../whatsnew/2.0.rst:986 msgid "" @@ -1482,16 +1947,29 @@ msgid "" "# the third child) before the 20th child.\n" "root.insertBefore( root.childNodes[0], root.childNodes[20] )" msgstr "" +"root = doc.documentElement\n" +"\n" +"# 移除第一個子節點\n" +"root.removeChild( root.childNodes[0] )\n" +"\n" +"# 將新的第一個子節點移到末尾\n" +"root.appendChild( root.childNodes[0] )\n" +"\n" +"# 將新的第一個子節點(原本是第三個子節點)\n" +"# 插入到第 20 個子節點之前。\n" +"root.insertBefore( root.childNodes[0], root.childNodes[20] )" #: ../../whatsnew/2.0.rst:998 msgid "" "Again, I will refer you to the Python documentation for a complete listing " "of the different :class:`!Node` classes and their various methods." msgstr "" +"我會再次將你引導至相對應的 Python 文件以取得不同 :class:`!Node` 類別及其各種方法的" +"完整列表。" #: ../../whatsnew/2.0.rst:1003 msgid "Relationship to PyXML" -msgstr "" +msgstr "與 PyXML 的關係" #: ../../whatsnew/2.0.rst:1005 msgid "" @@ -1502,6 +1980,10 @@ msgid "" "written programs that used PyXML, you're probably wondering about its " "compatibility with the 2.0 :mod:`xml` package." msgstr "" +"XML 專項興趣小組 (Special Interest Group) 這段時間以來一直在開發與 XML 相關的 " +"Python 程式碼。它的程式碼發布版稱為 PyXML,可從 SIG 的網頁 https://www.python.org/community/sigs/" +"current/xml-sig 取得。PyXML 發布版也使用 ``xml`` 作為套件名稱。如果你編寫過使用 " +"PyXML 的程式,你可能想知道它與 2.0 :mod:`xml` 套件的相容性。" #: ../../whatsnew/2.0.rst:1011 msgid "" @@ -1514,18 +1996,23 @@ msgid "" "a strict superset of the standard package, adding a bunch of additional " "features. Some of the additional features in PyXML include:" msgstr "" +"答案是 Python 2.0 的 :mod:`xml` 套件與 PyXML 不相容,但可以透過安裝最新版本的 " +"PyXML 來使其相容。許多應用程式可以使用 Python 2.0 附帶的 XML 支援,但更複雜的" +"應用程式需要安裝完整的 PyXML 套件。安裝後,PyXML 0.6.0 或更高版本將取代 " +"Python 附帶的 :mod:`xml` 套件,成為標準套件的嚴格超集,並新增一系列額外功能。" +"PyXML 中的一些額外功能包括:" #: ../../whatsnew/2.0.rst:1020 msgid "4DOM, a full DOM implementation from FourThought, Inc." -msgstr "" +msgstr "4DOM,來自 FourThought, Inc. 的完整 DOM 實作。" #: ../../whatsnew/2.0.rst:1022 msgid "The xmlproc validating parser, written by Lars Marius Garshol." -msgstr "" +msgstr "xmlproc 驗證剖析器,由 Lars Marius Garshol 編寫。" #: ../../whatsnew/2.0.rst:1024 msgid "The :mod:`!sgmlop` parser accelerator module, written by Fredrik Lundh." -msgstr "" +msgstr ":mod:`!sgmlop` 剖析器加速模組,由 Fredrik Lundh 編寫。" #: ../../whatsnew/2.0.rst:1030 msgid "Module changes" @@ -1540,6 +2027,11 @@ msgid "" "aifc`, :mod:`!chunk`, :mod:`wave`, :mod:`random`, :mod:`shelve`, and :mod:`!" "nntplib`. Consult the CVS logs for the exact patch-by-patch details." msgstr "" +"對 Python 龐大的標準函式庫進行了大量改進和錯誤修正;一些受影響的模組包括 " +":mod:`readline`、:mod:`ConfigParser `、:mod:`!cgi`、" +":mod:`calendar`、:mod:`posix`、:mod:`readline`、:mod:`!xmllib`、:mod:`!aifc`、" +":mod:`!chunk`、:mod:`wave`、:mod:`random`、:mod:`shelve` 和 :mod:`!nntplib`。請" +"查閱 CVS 日誌以取得補丁的確切詳情。" #: ../../whatsnew/2.0.rst:1038 msgid "" @@ -1553,12 +2045,18 @@ msgid "" "support ``https://`` URLs, though no one has implemented FTP or SMTP over " "SSL." msgstr "" +"Brian Gallew 為 :mod:`socket` 模組貢獻了 OpenSSL 支援。OpenSSL 是 Secure " +"Socket Layer 的實作,它會加密透過 socket 發送的資料。編譯 Python 時,你可以編" +"輯 :file:`Modules/Setup` 來包含 SSL 支援,這會在 :mod:`socket` 模組中新增一個" +"額外的函式:``socket.ssl(socket, keyfile, certfile)``,它接受一個 socket 物件" +"並回傳一個 SSL socket。:mod:`httplib ` 和 :mod:`urllib` 模組也被修改以支" +"援 ``https://`` URL,儘管還沒有人實作基於 SSL 的 FTP 或 SMTP。" #: ../../whatsnew/2.0.rst:1047 msgid "" "The :mod:`httplib ` module has been rewritten by Greg Stein to support " "HTTP/1.1." -msgstr "" +msgstr ":mod:`httplib ` 模組已由 Greg Stein 重寫以支援 HTTP/1.1。" #: ../../whatsnew/2.0.rst:1049 msgid "" @@ -1566,6 +2064,8 @@ msgid "" "though using HTTP/1.1 features such as pipelining will require rewriting " "code to use a different set of interfaces." msgstr "" +"提供了與 1.5 版本 :mod:`!httplib` 的向後相容性,但使用 HTTP/1.1 功能(如管線" +"化 (pipelining))將需要重寫程式碼以使用不同的介面集。" #: ../../whatsnew/2.0.rst:1053 msgid "" @@ -1575,6 +2075,10 @@ msgid "" "contributed an optimization which makes operations like ``create_line`` and " "``create_polygon`` much faster, especially when using lots of coordinates." msgstr "" +":mod:`!Tkinter` 模組現在支援 Tcl/Tk 版本 8.1、8.2 或 8.3,並且已放棄對舊版 7.x" +" 的支援。Tkinter 模組現在支援在 Tk widget 中顯示 Unicode 字串。此外,Fredrik " +"Lundh 貢獻了一項最佳化,使像 ``create_line`` 和 ``create_polygon`` 這樣的操作" +"變快許多,特別是在使用大量座標時。" #: ../../whatsnew/2.0.rst:1059 msgid "" @@ -1585,6 +2089,10 @@ msgid "" "operating systems that only have BSD curses, but there don't seem to be any " "currently maintained OSes that fall into this category." msgstr "" +":mod:`curses` 模組已大幅擴展,從 Oliver Andrich 的改進版本開始,提供了許多來自" +" ncurses 和 SYSV curses 的額外函式,如顏色、替代字元集支援、pad 和滑鼠支援。這" +"意味著該模組不再與只有 BSD curses 的作業系統相容,但似乎沒有任何目前仍在維護" +"的作業系統屬於這個類別。" #: ../../whatsnew/2.0.rst:1066 msgid "" @@ -1594,6 +2102,9 @@ msgid "" "written by Fredrik Lundh and partially funded by Hewlett Packard, supports " "matching against both 8-bit strings and Unicode strings." msgstr "" +"如同先前關於 2.0 Unicode 支援的討論中提到的,:mod:`re` 模組提供的正規表示式底" +"層實作已經改變。SRE 是一個由 Fredrik Lundh 編寫並由 Hewlett Packard 部分資助" +"的新正規表示式引擎,支援對 8 位元字串和 Unicode 字串進行匹配。" #: ../../whatsnew/2.0.rst:1076 msgid "New modules" @@ -1605,6 +2116,8 @@ msgid "" "descriptions; consult the 2.0 documentation for the details of a particular " "module." msgstr "" +"新增了一些模組。我們僅在此列出簡要描述;請參閱 2.0 說明文件以了解特定模組的詳" +"細資訊。" #: ../../whatsnew/2.0.rst:1082 msgid "" @@ -1614,12 +2127,18 @@ msgid "" "and calling :func:`atexit.register` with the function to be called on exit. " "(Contributed by Skip Montanaro.)" msgstr "" +":mod:`atexit`:用於註冊在 Python 直譯器退出前要呼叫的函式。目前直接設定 " +"``sys.exitfunc`` 的程式碼應改為使用 :mod:`atexit` 模組,引入 :mod:`atexit` 並" +"使用要在退出時呼叫的函式呼叫 :func:`atexit.register`。(由 Skip Montanaro 貢" +"獻。)" #: ../../whatsnew/2.0.rst:1088 msgid "" ":mod:`codecs`, :mod:`!encodings`, :mod:`unicodedata`: Added as part of the " "new Unicode support." msgstr "" +":mod:`codecs`、:mod:`!encodings`、:mod:`unicodedata`:作為新 Unicode 支援的一" +"部分而新增。" #: ../../whatsnew/2.0.rst:1091 msgid "" @@ -1627,6 +2146,8 @@ msgid "" "dircmp` modules, which have now become deprecated. (Contributed by Gordon " "MacMillan and Moshe Zadka.)" msgstr "" +":mod:`filecmp`:取代舊的 :mod:`!cmp`、:mod:`!cmpcache` 和 :mod:`!dircmp` 模" +"組,這些模組現已被棄用。(由 Gordon MacMillan 和 Moshe Zadka 貢獻。)" #: ../../whatsnew/2.0.rst:1095 msgid "" @@ -1636,6 +2157,9 @@ msgid "" "separate contributions by Martin von Löwis, Peter Funk, and James " "Henstridge.)" msgstr "" +":mod:`gettext`:此模組透過提供 GNU gettext 訊息目錄函式庫的介面,為 Python 程" +"式提供國際化 (I18N) 和本地化 (L10N) 支援。(由 Barry Warsaw 整合,來自 Martin " +"von Löwis、Peter Funk 和 James Henstridge 的個別貢獻。)" #: ../../whatsnew/2.0.rst:1100 msgid "" @@ -1643,6 +2167,8 @@ msgid "" "twin to the existing :mod:`!sunaudiodev` module. (Contributed by Peter " "Bosch, with fixes by Jeremy Hylton.)" msgstr "" +":mod:`!linuxaudiodev`:支援 Linux 上的 :file:`/dev/audio` 裝置,是現有 :mod:`!" +"sunaudiodev` 模組的孿生模組。(由 Peter Bosch 貢獻、Jeremy Hylton 修正。)" #: ../../whatsnew/2.0.rst:1104 msgid "" @@ -1653,12 +2179,17 @@ msgid "" "the :mod:`re` module. (Contributed by Sam Rushing, with some extensions by " "A.M. Kuchling.)" msgstr "" +":mod:`mmap`:Windows 和 Unix 上記憶體對映檔案的介面。檔案的內容可以直接對映到" +"記憶體中,此時它的行為就像一個可變字串,因此可以讀取和修改其內容。它們甚至可以" +"傳遞給預期要接受普通字串的函式,例如 :mod:`re` 模組。(由 Sam Rushing 貢獻,A.M. " +"Kuchling 進行了一些擴展。)" #: ../../whatsnew/2.0.rst:1110 msgid "" ":mod:`!pyexpat`: An interface to the Expat XML parser. (Contributed by Paul " "Prescod.)" msgstr "" +":mod:`!pyexpat`:Expat XML 剖析器的介面。(由 Paul Prescod 貢獻。)" #: ../../whatsnew/2.0.rst:1113 msgid "" @@ -1668,18 +2199,25 @@ msgid "" "builds a set of rules from it, and can then answer questions about the " "fetchability of a given URL. (Contributed by Skip Montanaro.)" msgstr "" +":mod:`robotparser `:剖析 :file:`robots.txt` 檔案,用於編" +"寫能禮貌地避開網站某些區域的網路爬蟲。剖析器接受 :file:`robots.txt` 檔案的內" +"容,並從中建立一組規則,然後可以回答關於給定 URL 是否可抓取的問題。(由 Skip " +"Montanaro 貢獻。)" #: ../../whatsnew/2.0.rst:1119 msgid "" ":mod:`tabnanny`: A module/script to check Python source code for ambiguous " "indentation. (Contributed by Tim Peters.)" msgstr "" +":mod:`tabnanny`:一個用於檢查 Python 原始碼中不明確縮排的模組/腳本。(由 Tim " +"Peters 貢獻。)" #: ../../whatsnew/2.0.rst:1122 msgid "" ":mod:`!UserString`: A base class useful for deriving objects that behave " "like strings." msgstr "" +":mod:`!UserString`:一個用於衍生行為類似字串的物件的基礎類別。" #: ../../whatsnew/2.0.rst:1125 msgid "" @@ -1692,6 +2230,11 @@ msgid "" "as :file:`Tools/idle/BrowserControl.py`, and adapted for the standard " "library by Fred.)" msgstr "" +":mod:`webbrowser`:一個不相依於平台、能以特定 URL 啟動網頁瀏覽器的模組。" +"對於各個平台,會依特定順序嘗試各種瀏覽器。使用者可以透過設定 *BROWSER* 環境變" +"數來更改啟動哪個瀏覽器。(最初受到 Eric S. Raymond 對 :mod:`urllib` 的補丁啟" +"發,該補丁新增了類似功能,但最終模組來自 Fred Drake 最初實作的 :file:`Tools/" +"idle/BrowserControl.py` 程式碼,並由 Fred 改編為標準函式庫。)" #: ../../whatsnew/2.0.rst:1134 msgid "" @@ -1701,6 +2244,9 @@ msgid "" "to support Unicode. :mod:`!_winreg` was written by Bill Tutt and Mark " "Hammond." msgstr "" +":mod:`_winreg `:Windows 登錄檔的介面。:mod:`!_winreg` 是自 1995 年以來" +"一直是 PythonWin 一部分函式的改編版本,但現在已被加入核心發布板,並被改進以支援" +" Unicode。:mod:`!_winreg` 由 Bill Tutt 和 Mark Hammond 編寫。" #: ../../whatsnew/2.0.rst:1139 msgid "" @@ -1709,6 +2255,10 @@ msgid "" "on Unix, not to be confused with :program:`gzip`\\ -format files (which are " "supported by the :mod:`gzip` module) (Contributed by James C. Ahlstrom.)" msgstr "" +":mod:`zipfile`:一個用於讀取和寫入 ZIP 格式封存檔案的模組。這些是由 DOS/Windows " +"上的 :program:`PKZIP` 或 Unix 上的 :program:`zip` 產生的封存檔案,不要與 " +":program:`gzip`\\ 格式的檔案(由 :mod:`gzip` 模組支援)混淆。(由 James C. " +"Ahlstrom 貢獻。)" #: ../../whatsnew/2.0.rst:1144 msgid "" @@ -1717,10 +2267,12 @@ msgid "" "(Implemented by Greg Stein, with much discussion on python-dev along the " "way.)" msgstr "" +":mod:`!imputil`:一個與現有的 :mod:`!ihooks` 模組相比,提供更簡單方式來編寫自" +"訂引入掛鉤的模組。(由 Greg Stein 實作,過程中在 python-dev 上有許多討論。)" #: ../../whatsnew/2.0.rst:1152 msgid "IDLE Improvements" -msgstr "" +msgstr "IDLE 改進" #: ../../whatsnew/2.0.rst:1154 msgid "" @@ -1728,58 +2280,63 @@ msgid "" "Python 2.0 includes IDLE 0.6, which adds a number of new features and " "improvements. A partial list:" msgstr "" +"IDLE 是官方的 Python 跨平台 IDE,使用 Tkinter 編寫。Python 2.0 包含 IDLE " +"0.6,新增了許多新功能和改進。部分列表如下:" #: ../../whatsnew/2.0.rst:1158 msgid "" "UI improvements and optimizations, especially in the area of syntax " "highlighting and auto-indentation." -msgstr "" +msgstr "UI 改進和最佳化,特別是在語法突顯 (syntax highlighting) 和自動縮排 (auto-indentation) 方面。" #: ../../whatsnew/2.0.rst:1161 msgid "" "The class browser now shows more information, such as the top level " "functions in a module." -msgstr "" +msgstr "類別瀏覽器現在顯示更多資訊,例如模組中的頂層函式。" #: ../../whatsnew/2.0.rst:1164 msgid "" "Tab width is now a user settable option. When opening an existing Python " "file, IDLE automatically detects the indentation conventions, and adapts." msgstr "" +"Tab 寬度現在是使用者可設定的選項。開啟現有的 Python 檔案時,IDLE 會自動偵測縮" +"排慣例並調整。" #: ../../whatsnew/2.0.rst:1167 msgid "" "There is now support for calling browsers on various platforms, used to open " "the Python documentation in a browser." -msgstr "" +msgstr "現在支援在各種平台上呼叫瀏覽器,用於在瀏覽器中開啟 Python 說明文件。" #: ../../whatsnew/2.0.rst:1170 msgid "" "IDLE now has a command line, which is largely similar to the vanilla Python " "interpreter." -msgstr "" +msgstr "IDLE 現在有一個命令列,與原版 Python 直譯器大致相似。" #: ../../whatsnew/2.0.rst:1173 msgid "Call tips were added in many places." -msgstr "" +msgstr "在許多地方新增了呼叫提示。" #: ../../whatsnew/2.0.rst:1175 msgid "IDLE can now be installed as a package." -msgstr "" +msgstr "IDLE 現在可以作為套件安裝。" #: ../../whatsnew/2.0.rst:1177 msgid "In the editor window, there is now a line/column bar at the bottom." -msgstr "" +msgstr "在編輯器視窗中,底部現在有一個行/列狀態列。" #: ../../whatsnew/2.0.rst:1179 msgid "" "Three new keystroke commands: Check module (:kbd:`Alt-F5`), Import module " "(:kbd:`F5`) and Run script (:kbd:`Ctrl-F5`)." msgstr "" +"三個新的按鍵命令:檢查模組(:kbd:`Alt-F5`)、引入模組(:kbd:`F5`)和執行腳本(:kbd:`Ctrl-F5`)。" #: ../../whatsnew/2.0.rst:1186 msgid "Deleted and Deprecated Modules" -msgstr "" +msgstr "已刪除和已棄用的模組" #: ../../whatsnew/2.0.rst:1188 msgid "" @@ -1788,6 +2345,8 @@ msgid "" "gone; it was for a platform-independent windowing toolkit that's no longer " "developed." msgstr "" +"一些模組因為已過時或因為現在有更好的方法來完成相同的事情而被移除。" +":mod:`!stdwin` 模組已被移除;它是用於一個不再開發的與平台無關的視窗工具組。" #: ../../whatsnew/2.0.rst:1192 msgid "" @@ -1799,6 +2358,11 @@ msgid "" "directory to ``sys.path`` to get them back, but you're encouraged to " "update any code that uses these modules." msgstr "" +"許多模組已被移至 :file:`lib-old` 子目錄::mod:`!cmp`、:mod:`!cmpcache`、" +":mod:`!dircmp`、:mod:`!dump`、:mod:`!find`、:mod:`!grep`、:mod:`!packmail`、" +":mod:`!poly`、:mod:`!util`、:mod:`!whatsound`、:mod:`!zmod`。如果你的程式碼依賴" +"於已被移至 :file:`lib-old` 的模組,你可以簡單地將該目錄加入 ``sys.path`` 來取回" +"它們,但建議你更新任何使用這些模組的程式碼。" #: ../../whatsnew/2.0.rst:1201 msgid "Acknowledgements" @@ -1812,3 +2376,7 @@ msgid "" "Skip Montanaro, Vladimir Marangozov, Tobias Polzin, Guido van Rossum, Neil " "Schemenauer, and Russ Schmidt." msgstr "" +"作者想感謝以下對本文各版本草稿提供建議的協力者:David Bolen、Mark Hammond、Gregg " +"Hauser、Jeremy Hylton、Fredrik Lundh、Detlef Lannert、Aahz Maruch、Skip " +"Montanaro、Vladimir Marangozov、Tobias Polzin、Guido van Rossum、Neil " +"Schemenauer 和 Russ Schmidt。"