@@ -32,34 +32,35 @@ msgid ""
3232":mod:`lib2to3` could also be adapted to custom applications in which Python "
3333"code needs to be edited automatically."
3434msgstr ""
35- "2to3 是一个 Python 程序,它可以用来读取 Python 2.x 版本的代码,并使用一系列的*fixer* 来将其转换为合法的 Python "
36- "3.x 代码。标准库中已经包含了丰富的 fixer,因此这足以处理绝大多数代码。然而 2to3 的支持库 :mod:`lib2to3` "
35+ "2to3 是一个 Python 程序,它可以用来读取 Python 2.x 版本的代码,并使用一系列的 *fixer* 来将其转换为合法的 Python"
36+ " 3.x 代码。标准库中已经包含了丰富的 fixer,这足以处理绝大多数代码。不过 2to3 的支持库 :mod:`lib2to3` "
3737"是一个很灵活通用的库,所以你也可以为 2to3 编写你自己的 fixer。:mod:`lib2to3` 也可以用在那些需要自动处理 Python "
3838"代码的应用中。"
3939
4040#: ../../library/2to3.rst:20
4141msgid "Using 2to3"
42- msgstr ""
42+ msgstr "使用 2to3 "
4343
4444#: ../../library/2to3.rst:22
4545msgid ""
4646"2to3 will usually be installed with the Python interpreter as a script. It "
4747"is also located in the :file:`Tools/scripts` directory of the Python root."
4848msgstr ""
49+ "2to3 通常会作为脚本和 Python 解释器一起安装,你可以在 Python 根目录的 :file:`Tools/scripts` 文件夹下找到它。"
4950
5051#: ../../library/2to3.rst:25
5152msgid ""
5253"2to3's basic arguments are a list of files or directories to transform. The"
5354" directories are recursively traversed for Python sources."
54- msgstr ""
55+ msgstr "2to3 的基本调用参数是一个需要转换的文件或目录列表。对于目录,会递归地寻找其中的 Python 源码。 "
5556
5657#: ../../library/2to3.rst:28
5758msgid "Here is a sample Python 2.x source file, :file:`example.py`::"
58- msgstr ""
59+ msgstr "这里有一个 Python 2.x 的源码文件,:file:`example.py`: "
5960
6061#: ../../library/2to3.rst:36
6162msgid "It can be converted to Python 3.x code via 2to3 on the command line:"
62- msgstr ""
63+ msgstr "它可以在命令行中使用 2to3 转换成 Python 3.x 版本的代码: "
6364
6465#: ../../library/2to3.rst:42
6566msgid ""
@@ -68,16 +69,18 @@ msgid ""
6869"original file is made unless :option:`!-n` is also given.) Writing the "
6970"changes back is enabled with the :option:`!-w` flag:"
7071msgstr ""
72+ "这个命令会打印出和源文件的区别。通过传入 :option:`!-w` 参数,2to3 也可以把需要的修改写回到原文件中(除非传入了 "
73+ ":option:`!-n` 参数,否则会为原始文件创建一个副本):"
7174
7275#: ../../library/2to3.rst:51
7376msgid "After transformation, :file:`example.py` looks like this::"
74- msgstr ""
77+ msgstr "在转换完成后,:file:`example.py` 看起来像是这样: "
7578
7679#: ../../library/2to3.rst:59
7780msgid ""
7881"Comments and exact indentation are preserved throughout the translation "
7982"process."
80- msgstr ""
83+ msgstr "注释和缩进都会在转换过程中保持不变。 "
8184
8285#: ../../library/2to3.rst:61
8386msgid ""
@@ -87,21 +90,27 @@ msgid ""
8790" disables a fixer. The following example runs only the ``imports`` and "
8891"``has_key`` fixers:"
8992msgstr ""
93+ "默认情况下,2to3 会执行 :ref:`预定义 fixers <2to3-fixers>` 的集合。使用 :option:`!-l` "
94+ "参数可以列出所有可用的 fixers。使用 :option:`!-f` 参数可以明确指定需要使用的 fixers 集合。而使用 "
95+ ":option:`!-x` 参数则可以明确指定不使用的 fixer。下面的例子会只使用 ``imports`` 和 ``has_key`` fixer "
96+ "运行:"
9097
9198#: ../../library/2to3.rst:70
9299msgid "This command runs every fixer except the ``apply`` fixer:"
93- msgstr ""
100+ msgstr "这个命令会执行除了 ``apply`` 之外的所有 fixer: "
94101
95102#: ../../library/2to3.rst:76
96103msgid ""
97104"Some fixers are *explicit*, meaning they aren't run by default and must be "
98105"listed on the command line to be run. Here, in addition to the default "
99106"fixers, the ``idioms`` fixer is run:"
100107msgstr ""
108+ "有一些 fixer 是需要*明确指定*的,它们默认不会执行,必须在命令行中列出才会执行。比如下面的例子,除了默认的 fixer 以外,还会执行 "
109+ "``idioms`` fixer:"
101110
102111#: ../../library/2to3.rst:84
103112msgid "Notice how passing ``all`` enables all default fixers."
104- msgstr ""
113+ msgstr "注意这里使用 ``all`` 来启用所有默认的 fixer。 "
105114
106115#: ../../library/2to3.rst:86
107116msgid ""
@@ -110,6 +119,8 @@ msgid ""
110119" warning beneath the diff for a file. You should address the warning in "
111120"order to have compliant 3.x code."
112121msgstr ""
122+ "有些情况下 2to3 会找到源码中有一些需要修改,但是无法自动处理的代码。在这种情况下,2to3 "
123+ "会在差异处下面打印一个警告信息。你应该定位到相应的代码并对其进行修改,以使其兼容 Python 3.x。"
113124
114125#: ../../library/2to3.rst:91
115126msgid ""
@@ -118,12 +129,14 @@ msgid ""
118129"require the module to be valid Python. For example, doctest like examples "
119130"in a reST document could also be refactored with this option."
120131msgstr ""
132+ "2to3 也可以重构 doctests。使用 :option:`!-d` 开启这个模式。需要注意*只有* doctests "
133+ "会被重构。这种模式下不需要文件是合法的 Python 代码。举例来说,reST 文档中类似 doctests 的示例也可以使用这个选项进行重构。"
121134
122135#: ../../library/2to3.rst:96
123136msgid ""
124137"The :option:`!-v` option enables output of more information on the "
125138"translation process."
126- msgstr ""
139+ msgstr ":option:`!-v` 选项可以输出更多转换程序的详细信息。 "
127140
128141#: ../../library/2to3.rst:99
129142msgid ""
@@ -135,6 +148,10 @@ msgid ""
135148"the :option:`!-p` flag. Use :option:`!-p` to run fixers on code that "
136149"already has had its print statements converted."
137150msgstr ""
151+ "由于一些 print 语句既可能是函数调用,也可能是代码语句,2to3 并不总是能读取含有 print 函数的文件。当 2to3 检测到代码中存在 "
152+ "``from __future__ import print_function`` 编译指令时,会在内部语法中将 :func:`print` "
153+ "作为函数来处理。这一变动也可以使用 :option:`!-p` 选项手动开启。使用 :option:`-p` 来为已经将 print "
154+ "语句转为函数调用的代码执行 fixer。"
138155
139156#: ../../library/2to3.rst:107
140157msgid ""
0 commit comments