context manager

03:33 Mar 15, 2021
English to Chinese translations [PRO]
Tech/Engineering - Computers (general)
English term or phrase: context manager
技术文档翻译
Nan Li
Canada


Summary of answers provided
5上下文管理器
Randy Wong
5上下文管理器
3178118 (X)
3 +1上下文管理器
Patrick Cheng
4境况管理器
Kiet Bach


  

Answers


56 mins   confidence: Answerer confidence 3/5Answerer confidence 3/5 peer agreement (net): +1
上下文管理器


Explanation:
without more specific context this is probably what I'll go with

Patrick Cheng
United States
Local time: 23:29
Specializes in field
Native speaker of: Native in ChineseChinese

Peer comments on this answer (and responses from the answerer)
agree  clearwater
1 day 17 hrs
Login to enter a peer comment (or grade)

6 hrs   confidence: Answerer confidence 5/5
上下文管理器


Explanation:
官网译法:

https://docs.python.org/zh-cn/3/library/unittest.mock-exampl...

----------------------------------------------------------------------------------
Mocking asynchronous context manager
Since Python 3.8, AsyncMock and MagicMock have support to mock 异步上下文管理器 through __aenter__ and __aexit__. By default, __aenter__ and __aexit__ are AsyncMock instances that return an async function.

Randy Wong
China
Local time: 13:29
Works in field
Native speaker of: Native in ChineseChinese
PRO pts in category: 4
Login to enter a peer comment (or grade)

14 hrs   confidence: Answerer confidence 5/5
上下文管理器


Explanation:
在官方技术文档中,有如下解释:
“context manager -- 上下文管理器
在 with 语句中使用,通过定义 __enter__() 和 __exit__() 方法来控制环境状态的对象。参见 PEP 343。”

简要地说,上下文管理器是指在一段代码执行之前执行一段代码,用于一些预处理工作;执行之后再执行一段代码,用于一些清理工作。比如打开文件进行读写,读写完之后需要将文件关闭。又比如在数据库操作中,操作之前需要连接数据库,操作之后需要关闭数据库。在上下文管理协议中,有两个方法__enter__和__exit__,分别实现上述两个功能。


Example sentence(s):
  • 关于上下文的定义,我就不在多言,具体通过程式来理解。既然提及上下文,就不可避免的涉及Python中关于上下文的魔法,即上下文管理器(contextor)。

    Reference: http://www.jianshu.com/p/d53449f9e7e0
3178118 (X)
Ireland
Local time: 05:29
Specializes in field
Native speaker of: Native in ChineseChinese
PRO pts in category: 8
Login to enter a peer comment (or grade)

5 hrs   confidence: Answerer confidence 4/5Answerer confidence 4/5
境况管理器


Explanation:
这些似乎都是 Python 电脑语言的用词,在以下可以找到:
https://docs.python.org/zh-cn/3/glossary.html

我提出的翻译与以上链接提供的不同。

Context Managers:
Context managers allow you to allocate and release resources precisely when you want to. The most widely used example of context managers is the with statement. Suppose you have two related operations which you’d like to execute as a pair, with a block of code in between. Context managers allow you to do specifically that.

--------------------------------------------------
Note added at 15 hrs (2021-03-15 18:51:25 GMT)
--------------------------------------------------

https://book.pythontips.com/en/latest/context_managers.html

Kiet Bach
United States
Local time: 22:29
Specializes in field
Native speaker of: Native in ChineseChinese
PRO pts in category: 4
Login to enter a peer comment (or grade)



Login or register (free and only takes a few minutes) to participate in this question.

You will also have access to many other tools and opportunities designed for those who have language-related jobs (or are passionate about them). Participation is free and the site has a strict confidentiality policy.

KudoZ™ translation help

The KudoZ network provides a framework for translators and others to assist each other with translations or explanations of terms and short phrases.


See also:
Term search
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search