当前位置:网站首页>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:运行顺序也标出来了
边栏推荐
猜你喜欢
随机推荐
LearnOpenGL - Introduction
MySQL视图
Entrepôt de données 4.0 Notes - acquisition de données sur le comportement de l'utilisateur II
Activiti7 Quick Start experience sharing
对.h5文件的迭代显示,h5py数据操作
11、多线程
循环队列
Yolov3关键代码解读
How to cast?
使用makefile编译ninja
ninja启动过程
New BPMN file used by activiti workflow
笔记 | 百度飞浆AI达人创造营:让人拍案叫绝的创意都是如何诞生的?
MySQL卸载
DBA command
Space shared by two stacks
[pyrodiomics] the extracted image omics characteristic value is abnormal (many 0 and 1)
Window runs gradle build ----- stacktrace. Exception occurs when the file framework-4.3.0.build-snapshot-schema.zip is not found
查看真机APP里面沙盒文件
Kubesphere haproxy+kept (I)









