@@ -5291,6 +5291,8 @@ msgid ""
52915291"that allow user-defined classes to define a runtime context that is entered "
52925292"before the statement body is executed and exited when the statement ends:"
52935293msgstr ""
5294+ "Python 的 :keyword:`with` 语句支持通过上下文管理器所定义的运行时上下文这一概念。 "
5295+ "此对象的实现使用了一对专门方法,允许用户自定义类来定义运行时上下文,在语句体被执行前进入该上下文,并在语句执行完毕时退出该上下文:"
52945296
52955297#: ../../library/stdtypes.rst:4394
52965298msgid ""
@@ -5299,6 +5301,8 @@ msgid ""
52995301"to the identifier in the :keyword:`!as` clause of :keyword:`with` statements"
53005302" using this context manager."
53015303msgstr ""
5304+ "进入运行时上下文并返回此对象或关联到该运行时上下文的其他对象。 此方法的返回值会绑定到使用此上下文管理器的 :keyword:`with` 语句的 "
5305+ ":keyword:`!as` 子句中的标识符。"
53025306
53035307#: ../../library/stdtypes.rst:4399
53045308msgid ""
@@ -5307,6 +5311,8 @@ msgid ""
53075311":func:`open` to be used as the context expression in a :keyword:`with` "
53085312"statement."
53095313msgstr ""
5314+ "一个返回其自身的上下文管理器的例子是 :term:`file object`。 文件对象会从 __enter__() 返回其自身,以允许 "
5315+ ":func:`open` 被用作 :keyword:`with` 语句中的上下文表达式。"
53105316
53115317#: ../../library/stdtypes.rst:4403
53125318msgid ""
@@ -5317,6 +5323,9 @@ msgid ""
53175323"the body of the :keyword:`with` statement without affecting code outside the"
53185324" :keyword:`!with` statement."
53195325msgstr ""
5326+ "一个返回关联对象的上下文管理器的例子是 :func:`decimal.localcontext` 所返回的对象。 此种管理器会将活动的 decimal "
5327+ "上下文设为原始 decimal 上下文的一个副本并返回该副本。 这允许对 :keyword:`with` 语句的语句体中的当前 decimal "
5328+ "上下文进行更改,而不会影响 :keyword:`!with` 语句以外的代码。"
53205329
53215330#: ../../library/stdtypes.rst:4413
53225331msgid ""
@@ -5326,6 +5335,8 @@ msgid ""
53265335"the exception type, value and traceback information. Otherwise, all three "
53275336"arguments are ``None``."
53285337msgstr ""
5338+ "退出运行时上下文并返回一个布尔值旗标来表明所发生的任何异常是否应当被屏蔽。 如果在执行 :keyword:`with` "
5339+ "语句的语句体期间发生了异常,则参数会包含异常的类型、值以及回溯信息。 在其他情况下三个参数均为 ``None``。"
53295340
53305341#: ../../library/stdtypes.rst:4418
53315342msgid ""
0 commit comments