@@ -18,7 +18,7 @@ msgid ""
1818msgstr ""
1919"Project-Id-Version : Python 3.9\n "
2020"Report-Msgid-Bugs-To : \n "
21- "POT-Creation-Date : 2021-01-01 05:02 +0000\n "
21+ "POT-Creation-Date : 2021-04-04 05:56 +0000\n "
2222"PO-Revision-Date : 2017-02-16 17:43+0000\n "
2323"Last-Translator : Freesand Leo <yuqinju@163.com>, 2020\n "
2424"Language-Team : Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -2084,14 +2084,106 @@ msgstr ""
20842084"这两个id属于之前创建的不同整数对象,并在执行 ``id()`` 调用后立即删除。要确保要检查其id的对象仍处于活动状态,请创建对该对象的另一个引用:"
20852085
20862086#: ../../faq/programming.rst:1706
2087+ msgid "When can I rely on identity tests with the *is* operator?"
2088+ msgstr ""
2089+
2090+ #: ../../faq/programming.rst:1708
2091+ msgid ""
2092+ "The ``is`` operator tests for object identity. The test ``a is b`` is "
2093+ "equivalent to ``id(a) == id(b)``."
2094+ msgstr ""
2095+
2096+ #: ../../faq/programming.rst:1711
2097+ msgid ""
2098+ "The most important property of an identity test is that an object is always "
2099+ "identical to itself, ``a is a`` always returns ``True``. Identity tests are"
2100+ " usually faster than equality tests. And unlike equality tests, identity "
2101+ "tests are guaranteed to return a boolean ``True`` or ``False``."
2102+ msgstr ""
2103+
2104+ #: ../../faq/programming.rst:1716
2105+ msgid ""
2106+ "However, identity tests can *only* be substituted for equality tests when "
2107+ "object identity is assured. Generally, there are three circumstances where "
2108+ "identity is guaranteed:"
2109+ msgstr ""
2110+
2111+ #: ../../faq/programming.rst:1720
2112+ msgid ""
2113+ "1) Assignments create new names but do not change object identity. After "
2114+ "the assignment ``new = old``, it is guaranteed that ``new is old``."
2115+ msgstr ""
2116+
2117+ #: ../../faq/programming.rst:1723
2118+ msgid ""
2119+ "2) Putting an object in a container that stores object references does not "
2120+ "change object identity. After the list assignment ``s[0] = x``, it is "
2121+ "guaranteed that ``s[0] is x``."
2122+ msgstr ""
2123+
2124+ #: ../../faq/programming.rst:1727
2125+ msgid ""
2126+ "3) If an object is a singleton, it means that only one instance of that "
2127+ "object can exist. After the assignments ``a = None`` and ``b = None``, it "
2128+ "is guaranteed that ``a is b`` because ``None`` is a singleton."
2129+ msgstr ""
2130+
2131+ #: ../../faq/programming.rst:1731
2132+ msgid ""
2133+ "In most other circumstances, identity tests are inadvisable and equality "
2134+ "tests are preferred. In particular, identity tests should not be used to "
2135+ "check constants such as :class:`int` and :class:`str` which aren't "
2136+ "guaranteed to be singletons::"
2137+ msgstr ""
2138+
2139+ #: ../../faq/programming.rst:1748
2140+ msgid "Likewise, new instances of mutable containers are never identical::"
2141+ msgstr ""
2142+
2143+ #: ../../faq/programming.rst:1755
2144+ msgid ""
2145+ "In the standard library code, you will see several common patterns for "
2146+ "correctly using identity tests:"
2147+ msgstr ""
2148+
2149+ #: ../../faq/programming.rst:1758
2150+ msgid ""
2151+ "1) As recommended by :pep:`8`, an identity test is the preferred way to "
2152+ "check for ``None``. This reads like plain English in code and avoids "
2153+ "confusion with other objects that may have boolean values that evaluate to "
2154+ "false."
2155+ msgstr ""
2156+
2157+ #: ../../faq/programming.rst:1762
2158+ msgid ""
2159+ "2) Detecting optional arguments can be tricky when ``None`` is a valid input"
2160+ " value. In those situations, you can create an singleton sentinel object "
2161+ "guaranteed to be distinct from other objects. For example, here is how to "
2162+ "implement a method that behaves like :meth:`dict.pop`::"
2163+ msgstr ""
2164+
2165+ #: ../../faq/programming.rst:1778
2166+ msgid ""
2167+ "3) Container implementations sometimes need to augment equality tests with "
2168+ "identity tests. This prevents the code from being confused by objects such "
2169+ "as ``float('NaN')`` that are not equal to themselves."
2170+ msgstr ""
2171+
2172+ #: ../../faq/programming.rst:1782
2173+ msgid ""
2174+ "For example, here is the implementation of "
2175+ ":meth:`collections.abc.Sequence.__contains__`::"
2176+ msgstr ""
2177+
2178+ #: ../../faq/programming.rst:1793
20872179msgid "Modules"
20882180msgstr "模块"
20892181
2090- #: ../../faq/programming.rst:1709
2182+ #: ../../faq/programming.rst:1796
20912183msgid "How do I create a .pyc file?"
20922184msgstr "如何创建 .pyc 文件?"
20932185
2094- #: ../../faq/programming.rst:1711
2186+ #: ../../faq/programming.rst:1798
20952187msgid ""
20962188"When a module is imported for the first time (or when the source file has "
20972189"changed since the current compiled file was created) a ``.pyc`` file "
@@ -2106,7 +2198,7 @@ msgstr ""
21062198"子目录下创建一个包含已编译代码的 ``.pyc`` 文件。 该 ``.pyc`` 文件的文件名的开头部分将与对应 ``.py`` 文件名相同,并以 "
21072199"``.pyc`` 为后缀,中间部门则是基于创建它的特定 ``python`` 二进制代码版本。 (详情参见 :pep:`3147`。)"
21082200
2109- #: ../../faq/programming.rst:1719
2201+ #: ../../faq/programming.rst:1806
21102202msgid ""
21112203"One reason that a ``.pyc`` file may not be created is a permissions problem "
21122204"with the directory containing the source file, meaning that the "
@@ -2117,7 +2209,7 @@ msgstr ""
21172209"无法创建 ``.pyc`` 文件的可能原因是包含源文件的目录存在权限问题,这意味着 ``__pycache__`` 子目录无法被创建。 "
21182210"举例来说,如果你以某一用户来开发程序但以另一用户身份来运行程序时就可能发生问题,测试 Web 服务器就属于这种情况。"
21192211
2120- #: ../../faq/programming.rst:1724
2212+ #: ../../faq/programming.rst:1811
21212213msgid ""
21222214"Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, "
21232215"creation of a .pyc file is automatic if you're importing a module and Python"
@@ -2128,7 +2220,7 @@ msgstr ""
21282220"除非设置了 :envvar:`PYTHONDONTWRITEBYTECODE` 环境变量,否则当你导入模块并且 Python 具有创建 "
21292221"``__pycache__`` 子目录并将已编译模块写入该子目录的能力(权限、存储空间等等)时就会自动创建 .pyc 文件。"
21302222
2131- #: ../../faq/programming.rst:1729
2223+ #: ../../faq/programming.rst:1816
21322224msgid ""
21332225"Running Python on a top level script is not considered an import and no "
21342226"``.pyc`` will be created. For example, if you have a top-level module "
@@ -2142,7 +2234,7 @@ msgstr ""
21422234"foo.py``),则将为 ``xyz`` 创建一个 ``.pyc``,因为 ``xyz`` 是被导入的,但不会为 ``foo`` 创建 "
21432235"``.pyc`` 文件,因为 ``foo.py`` 不是被导入的。"
21442236
2145- #: ../../faq/programming.rst:1736
2237+ #: ../../faq/programming.rst:1823
21462238msgid ""
21472239"If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a "
21482240"``.pyc`` file for a module that is not imported -- you can, using the "
@@ -2151,13 +2243,13 @@ msgstr ""
21512243"如果你需要为 ``foo`` 创建 ``.pyc`` 文件 —— 即为不是被导入的模块创建 ``.pyc`` 文件 —— 你可以使用 "
21522244":mod:`py_compile` 和 :mod:`compileall` 模块。"
21532245
2154- #: ../../faq/programming.rst:1740
2246+ #: ../../faq/programming.rst:1827
21552247msgid ""
21562248"The :mod:`py_compile` module can manually compile any module. One way is to"
21572249" use the ``compile()`` function in that module interactively::"
21582250msgstr ":mod:`py_compile` 模块能够手动编译任意模块。 一种做法是交互式地使用该模块中的 ``compile()`` 函数::"
21592251
2160- #: ../../faq/programming.rst:1746
2252+ #: ../../faq/programming.rst:1833
21612253msgid ""
21622254"This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same "
21632255"location as ``foo.py`` (or you can override that with the optional parameter"
@@ -2166,7 +2258,7 @@ msgstr ""
21662258"这将会将 ``.pyc`` 文件写入与 ``foo.py`` 相同位置下的 ``__pycache__`` 子目录(或者你也可以通过可选参数 "
21672259"``cfile`` 来重载该行为)。"
21682260
2169- #: ../../faq/programming.rst:1750
2261+ #: ../../faq/programming.rst:1837
21702262msgid ""
21712263"You can also automatically compile all files in a directory or directories "
21722264"using the :mod:`compileall` module. You can do it from the shell prompt by "
@@ -2176,11 +2268,11 @@ msgstr ""
21762268"你还可以使用 :mod:`compileall` 模块自动编译一个目录或多个目录下的所有文件。 具体做法可以是在命令行提示符中运行 "
21772269"``compileall.py`` 并提供包含要编译 Python 文件的目录路径::"
21782270
2179- #: ../../faq/programming.rst:1759
2271+ #: ../../faq/programming.rst:1846
21802272msgid "How do I find the current module name?"
21812273msgstr "如何找到当前模块名称?"
21822274
2183- #: ../../faq/programming.rst:1761
2275+ #: ../../faq/programming.rst:1848
21842276msgid ""
21852277"A module can find out its own module name by looking at the predefined "
21862278"global variable ``__name__``. If this has the value ``'__main__'``, the "
@@ -2191,76 +2283,76 @@ msgstr ""
21912283"模块可以通过查看预定义的全局变量 ``__name__`` 找到自己的模块名称。如果它的值为 ``'__main__'`` "
21922284",程序将作为脚本运行。通常,通过导入使用的许多模块也提供命令行界面或自检,并且只在检查 ``__name__`` 之后,才执行之后的代码::"
21932285
2194- #: ../../faq/programming.rst:1776
2286+ #: ../../faq/programming.rst:1863
21952287msgid "How can I have modules that mutually import each other?"
21962288msgstr "如何让模块相互导入?"
21972289
2198- #: ../../faq/programming.rst:1778
2290+ #: ../../faq/programming.rst:1865
21992291msgid "Suppose you have the following modules:"
22002292msgstr "假设您有以下模块:"
22012293
2202- #: ../../faq/programming.rst:1780
2294+ #: ../../faq/programming.rst:1867
22032295msgid "foo.py::"
22042296msgstr "foo.py::"
22052297
2206- #: ../../faq/programming.rst:1785
2298+ #: ../../faq/programming.rst:1872
22072299msgid "bar.py::"
22082300msgstr "bar.py::"
22092301
2210- #: ../../faq/programming.rst:1790
2302+ #: ../../faq/programming.rst:1877
22112303msgid "The problem is that the interpreter will perform the following steps:"
22122304msgstr "问题是解释器将执行以下步骤:"
22132305
2214- #: ../../faq/programming.rst:1792
2306+ #: ../../faq/programming.rst:1879
22152307msgid "main imports foo"
22162308msgstr "首先导入foo"
22172309
2218- #: ../../faq/programming.rst:1793
2310+ #: ../../faq/programming.rst:1880
22192311msgid "Empty globals for foo are created"
22202312msgstr "创建用于foo的空全局变量"
22212313
2222- #: ../../faq/programming.rst:1794
2314+ #: ../../faq/programming.rst:1881
22232315msgid "foo is compiled and starts executing"
22242316msgstr "foo被编译并开始执行"
22252317
2226- #: ../../faq/programming.rst:1795
2318+ #: ../../faq/programming.rst:1882
22272319msgid "foo imports bar"
22282320msgstr "foo 导入 bar"
22292321
2230- #: ../../faq/programming.rst:1796
2322+ #: ../../faq/programming.rst:1883
22312323msgid "Empty globals for bar are created"
22322324msgstr "创建了用于bar 的空全局变量"
22332325
2234- #: ../../faq/programming.rst:1797
2326+ #: ../../faq/programming.rst:1884
22352327msgid "bar is compiled and starts executing"
22362328msgstr "bar被编译并开始执行"
22372329
2238- #: ../../faq/programming.rst:1798
2330+ #: ../../faq/programming.rst:1885
22392331msgid ""
22402332"bar imports foo (which is a no-op since there already is a module named foo)"
22412333msgstr "bar导入foo(这是一个空操作(no-op ),因为已经有一个名为foo的模块)"
22422334
2243- #: ../../faq/programming.rst:1799
2335+ #: ../../faq/programming.rst:1886
22442336msgid "bar.foo_var = foo.foo_var"
22452337msgstr "bar.foo_var = foo.foo_var"
22462338
2247- #: ../../faq/programming.rst:1801
2339+ #: ../../faq/programming.rst:1888
22482340msgid ""
22492341"The last step fails, because Python isn't done with interpreting ``foo`` yet"
22502342" and the global symbol dictionary for ``foo`` is still empty."
22512343msgstr "最后一步失败了,因为Python还没有解释foo,而foo的全局符号字典仍然是空的。"
22522344
2253- #: ../../faq/programming.rst:1804
2345+ #: ../../faq/programming.rst:1891
22542346msgid ""
22552347"The same thing happens when you use ``import foo``, and then try to access "
22562348"``foo.foo_var`` in global code."
22572349msgstr "当你使用 ``import foo`` ,然后尝试在全局代码中访问 ``foo.foo_var`` 时,会发生同样的事情。"
22582350
2259- #: ../../faq/programming.rst:1807
2351+ #: ../../faq/programming.rst:1894
22602352msgid "There are (at least) three possible workarounds for this problem."
22612353msgstr "这个问题有(至少)三种可能的解决方法。"
22622354
2263- #: ../../faq/programming.rst:1809
2355+ #: ../../faq/programming.rst:1896
22642356msgid ""
22652357"Guido van Rossum recommends avoiding all uses of ``from <module> import "
22662358"...``, and placing all code inside functions. Initializations of global "
@@ -2272,59 +2364,59 @@ msgstr ""
22722364",并将所有代码放在函数中。全局变量和类变量的初始化只能使用常量或内置函数。这意味着导入模块中的所有内容都被引用为 ``<module>.<name>``"
22732365" 。"
22742366
2275- #: ../../faq/programming.rst:1814
2367+ #: ../../faq/programming.rst:1901
22762368msgid ""
22772369"Jim Roskind suggests performing steps in the following order in each module:"
22782370msgstr "Jim Roskind建议在每个模块中按以下顺序执行步骤:"
22792371
2280- #: ../../faq/programming.rst:1816
2372+ #: ../../faq/programming.rst:1903
22812373msgid ""
22822374"exports (globals, functions, and classes that don't need imported base "
22832375"classes)"
22842376msgstr "导出(全局变量,函数和不需要导入基类的类)"
22852377
2286- #: ../../faq/programming.rst:1818
2378+ #: ../../faq/programming.rst:1905
22872379msgid "``import`` statements"
22882380msgstr "``导入`` 声明"
22892381
2290- #: ../../faq/programming.rst:1819
2382+ #: ../../faq/programming.rst:1906
22912383msgid ""
22922384"active code (including globals that are initialized from imported values)."
22932385msgstr "活动代码(包括从导入值初始化的全局变量)。"
22942386
2295- #: ../../faq/programming.rst:1821
2387+ #: ../../faq/programming.rst:1908
22962388msgid ""
22972389"van Rossum doesn't like this approach much because the imports appear in a "
22982390"strange place, but it does work."
22992391msgstr "van Rossum不喜欢这种方法,因为导入出现在一个陌生的地方,但这种方法确实有效。"
23002392
2301- #: ../../faq/programming.rst:1824
2393+ #: ../../faq/programming.rst:1911
23022394msgid ""
23032395"Matthias Urlichs recommends restructuring your code so that the recursive "
23042396"import is not necessary in the first place."
23052397msgstr "Matthias Urlichs建议重构代码,以便首先不需要递归导入。"
23062398
2307- #: ../../faq/programming.rst:1827
2399+ #: ../../faq/programming.rst:1914
23082400msgid "These solutions are not mutually exclusive."
23092401msgstr "这些解决方案并不相互排斥。"
23102402
2311- #: ../../faq/programming.rst:1831
2403+ #: ../../faq/programming.rst:1918
23122404msgid "__import__('x.y.z') returns <module 'x'>; how do I get z?"
23132405msgstr "__import__('x.y.z') 返回 <module 'x'>; 如何获取z?"
23142406
2315- #: ../../faq/programming.rst:1833
2407+ #: ../../faq/programming.rst:1920
23162408msgid ""
23172409"Consider using the convenience function :func:`~importlib.import_module` "
23182410"from :mod:`importlib` instead::"
23192411msgstr "考虑使用 :mod:`importlib` 中的函数 :func:`~importlib.import_module` :"
23202412
2321- #: ../../faq/programming.rst:1840
2413+ #: ../../faq/programming.rst:1927
23222414msgid ""
23232415"When I edit an imported module and reimport it, the changes don't show up. "
23242416"Why does this happen?"
23252417msgstr "当我编辑了导入过的模块并重新导入它时,这些变化没有显示出来。为什么会这样?"
23262418
2327- #: ../../faq/programming.rst:1842
2419+ #: ../../faq/programming.rst:1929
23282420msgid ""
23292421"For reasons of efficiency as well as consistency, Python only reads the "
23302422"module file on the first time a module is imported. If it didn't, in a "
@@ -2334,21 +2426,21 @@ msgid ""
23342426msgstr ""
23352427"出于效率和一致性的原因,Python仅在第一次导入模块时读取模块文件。如果不这么做,在一个由许多模块组成的程序中,每个模块都会导入相同的基本模块,那么基本模块将被解析和重新解析多次。要强制重新读取已更改的模块,请执行以下操作::"
23362428
2337- #: ../../faq/programming.rst:1852
2429+ #: ../../faq/programming.rst:1939
23382430msgid ""
23392431"Warning: this technique is not 100% fool-proof. In particular, modules "
23402432"containing statements like ::"
23412433msgstr "警告:这种技术不是100%万无一失。特别是包含如下语句的模块"
23422434
2343- #: ../../faq/programming.rst:1857
2435+ #: ../../faq/programming.rst:1944
23442436msgid ""
23452437"will continue to work with the old version of the imported objects. If the "
23462438"module contains class definitions, existing class instances will *not* be "
23472439"updated to use the new class definition. This can result in the following "
23482440"paradoxical behaviour::"
23492441msgstr "将继续使用旧版本的导入对象。如果模块包含类定义,则不会更新现有的类实例以使用新的类定义。这可能导致以下矛盾行为::"
23502442
2351- #: ../../faq/programming.rst:1870
2443+ #: ../../faq/programming.rst:1957
23522444msgid ""
23532445"The nature of the problem is made clear if you print out the \" identity\" of"
23542446" the class objects::"
0 commit comments