当前位置:网站首页>with语句
with语句
2022-07-23 05:42:00 【AutoGalaxy】
一. with语句
用法:with a() as b:
(1)with后面的类实例化要是上下文管理器,即上面的a类
上下文管理器,长成下面这个样子,
class a(object):
def __init__(self):
print("a__init__") #1
def __enter__(self):
print("enter")
return self.process #2
def __exit__(self):
print("exit")
self.process.close() #4其中的process是一个类,必须长这个样子
class process(object):
def __init__(self):
print("process") #3
def close(self):
print("close") #5当执行下述命令
with a() as b:运行顺序也标出来了
边栏推荐
猜你喜欢

Mosaic the face part of the picture

Data warehouse 4.0 notes - user behavior data collection II

New BPMN file used by activiti workflow

飞桨高层API实现人脸关键点检测

Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!

Data warehouse 4.0 notes - business data collection - sqoop

ChaosLibrary·UE4开坑笔记
![[pyrodiomics] the extracted image omics characteristic value is abnormal (many 0 and 1)](/img/73/628e0188e1e2c13e0963746759f691.png)
[pyrodiomics] the extracted image omics characteristic value is abnormal (many 0 and 1)

Using cluster analysis to build a credit card high-risk customer identification model

方法的定义应用
随机推荐
Software test 1
Introduction and use of Ninja
抽象类和接口有什么区别?
Linked list related interview questions
Definition and application of method
ChaosLibrary·UE4开坑笔记
2. MySQL data management - DML (add, modify, delete data)
Window runs gradle build ----- stacktrace. Exception occurs when the file framework-4.3.0.build-snapshot-schema.zip is not found
双端队列
Data warehouse 4.0 notes - user behavior data collection IV
MySQL用户管理
VMware uses wireless network card NAT to access the Internet under Windows
10. I/o input / output stream
What is the IP address
Modify the root password of MySQL
Develop necessary idea use
Double ended queue
UItextview的textViewDidChange的使用技巧
Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!
1. Initial experience of MySQL