gpt4 book ai didi

python - 上下文管理器类 ("with" block 的命名约定)

转载 作者:太空狗 更新时间:2023-10-30 01:29:20 25 4
gpt4 key购买 nike

对于要在 with block 中使用的类或函数,是否有通用的命名约定,例如

with CreateSomeContext() as x:
...

?表明类或函数的结果应该与 with 一起使用的东西?

最佳答案

the respective PEP 0343 , 提到了两个约定:

The tense used in the names of the example contexts is not arbitrary. Past tense ("-ed") is used when the name refers to an action which is done in the __enter__ method and undone in the __exit__ method. Progressive tense ("-ing") is used when the name refers to an action which is to be done in the __exit__ method.

关于python - 上下文管理器类 ("with" block 的命名约定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19948457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com