@@ -89,6 +89,9 @@ msgid ""
8989"letters with no intervening spaces. Writing ``$$`` creates a single escaped"
9090" ``$``::"
9191msgstr ""
92+ "上述格式化操作是通过占位符实现的,占位符由 ``$`` 加上合法的 Python "
93+ "标识符(只能包含字母、数字和下划线)构成。一旦使用花括号将占位符括起来,就可以在后面直接跟上更多的字母和数字而无需空格分割。``$$`` "
94+ "将被转义成单个字符 ``$``::"
9295
9396#: ../../tutorial/stdlib2.rst:88
9497msgid ""
@@ -98,21 +101,25 @@ msgid ""
98101":meth:`~string.Template.safe_substitute` method may be more appropriate --- "
99102"it will leave placeholders unchanged if data is missing::"
100103msgstr ""
104+ "如果在字典或关键字参数中未提供某个占位符的值,那么 :meth:`~string.Template.substitute` 方法将抛出 "
105+ ":exc:`KeyError`\\ 。对于邮件合并类型的应用,用户提供的数据有可能是不完整的,此时使用 "
106+ ":meth:`~string.Template.safe_substitute` 方法更加合适 —— 如果数据缺失,它会直接将占位符原样保留。"
101107
102108#: ../../tutorial/stdlib2.rst:103
103109msgid ""
104110"Template subclasses can specify a custom delimiter. For example, a batch "
105111"renaming utility for a photo browser may elect to use percent signs for "
106112"placeholders such as the current date, image sequence number, or file "
107113"format::"
108- msgstr ""
114+ msgstr "Template 的子类可以自定义定界符。例如,以下是某个照片浏览器的批量重命名功能,采用了百分号作为日期、照片序号和照片格式的占位符:: "
109115
110116#: ../../tutorial/stdlib2.rst:125
111117msgid ""
112118"Another application for templating is separating program logic from the "
113119"details of multiple output formats. This makes it possible to substitute "
114120"custom templates for XML files, plain text reports, and HTML web reports."
115121msgstr ""
122+ "模板的另一个应用是将程序逻辑与多样的格式化输出细节分离开来。这使得对 XML 文件、纯文本报表和 HTML 网络报表使用自定义模板成为可能。"
116123
117124#: ../../tutorial/stdlib2.rst:133
118125msgid "Working with Binary Data Record Layouts"
@@ -128,6 +135,10 @@ msgid ""
128135"respectively. The ``\" <\" `` indicates that they are standard size and in "
129136"little-endian byte order::"
130137msgstr ""
138+ ":mod:`struct` 模块提供了 :func:`~struct.pack` 和 :func:`~struct.unpack` "
139+ "函数,用于处理不定长度的二进制记录格式。下面的例子展示了在不使用 :mod:`zipfile` 模块的情况下,如何循环遍历一个 ZIP "
140+ "文件的所有头信息。Pack 代码 ``\" H\" `` 和 ``\" I\" `` 分别代表两字节和四字节无符号整数。\\ ``\" <\" `` "
141+ "代表它们是标准尺寸的小尾型字节序::"
131142
132143#: ../../tutorial/stdlib2.rst:166
133144msgid "Multi-threading"
@@ -141,12 +152,14 @@ msgid ""
141152" A related use case is running I/O in parallel with computations in another"
142153" thread."
143154msgstr ""
155+ "线程是一种对于非顺序依赖的多个任务进行解耦的技术。多线程可以提高应用的响应效率,当接收用户输入的同时,保持其他任务在后台运行。一个有关的应用场景是,将 "
156+ "I/O 和计算运行在两个并行的线程中。"
144157
145158#: ../../tutorial/stdlib2.rst:173
146159msgid ""
147160"The following code shows how the high level :mod:`threading` module can run "
148161"tasks in background while the main program continues to run::"
149- msgstr "以下代码展示了高级模块 :mod:`threading` 如何在后台运行任务,且不影响主程序继续运行 ::"
162+ msgstr "以下代码展示了高阶的 :mod:`threading` 模块如何在后台运行任务,且不影响主程序的继续运行 ::"
150163
151164#: ../../tutorial/stdlib2.rst:197
152165msgid ""
@@ -155,6 +168,8 @@ msgid ""
155168"module provides a number of synchronization primitives including locks, "
156169"events, condition variables, and semaphores."
157170msgstr ""
171+ "多线程应用面临的主要挑战是,相互协调的多个线程之间需要共享数据或其他资源。为此,threading "
172+ "模块提供了多个同步操作原语,包括线程锁、事件、条件变量和信号量。"
158173
159174#: ../../tutorial/stdlib2.rst:202
160175msgid ""
@@ -166,10 +181,13 @@ msgid ""
166181"thread communication and coordination are easier to design, more readable, "
167182"and more reliable."
168183msgstr ""
184+ "尽管这些工具非常强大,但微小的设计错误却可以导致一些难以复现的问题。因此,实现多任务协作的首选方法是将对资源的所有请求集中到一个线程中,然后使用 "
185+ ":mod:`queue` 模块向该线程供应来自其他线程的请求。应用程序使用 :class:`~queue.Queue` "
186+ "对象进行线程间通信和协调,更易于设计,更易读,更可靠。"
169187
170188#: ../../tutorial/stdlib2.rst:213
171189msgid "Logging"
172- msgstr "日志Logging "
190+ msgstr "日志 "
173191
174192#: ../../tutorial/stdlib2.rst:215
175193msgid ""
0 commit comments